GithubHelp home page GithubHelp logo

frozen-jelly / tensorsem Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vankesteren/tensorsem

0.0 1.0 0.0 128 KB

Structural Equation Modeling using Torch

License: GNU General Public License v3.0

R 20.04% Python 79.96%

tensorsem's Introduction


DOI

Structural Equation Modeling using Torch


Description

An R and python package for structural equation modeling using Torch. This package is meant for researchers who know their way around SEM, Torch, and lavaan. Structural equation modeling is implemented as a fully functional torch.nn module. A short example optimization loop would be:

import tensorsem as ts
model = ts.StructuralEquationModel(opt = opts)  # opts are of class SemOptions
optim = torch.optim.Adam(model.parameters())  # init the optimizer
for epoch in range(1000):
    optim.zero_grad()  # reset the gradients of the parameters
    Sigma = model()  # compute the model-implied covariance matrix
    loss = ts.mvn_negloglik(dat, Sigma)  # compute the negative log-likelihood, dat tensor should exist
    loss.backward()  # compute the gradients and store them in the parameter tensors
    optim.step()  # take a step in the negative gradient direction using adam

Installation

To install the latest version of tensorsem, run the following:

  1. Install the R interface package from this repository:
    remotes::install_github("vankesteren/tensorsem")
  2. Install pytorch on your system. Use the pytorch website to do this. For example, for a windows pip cpu version, use:
    pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
  3. Install the tensorsem python package from this repository.
    pip install https://github.com/vankesteren/tensorsem/archive/master.zip
  4. (Optional) Install pandas and matplotlib for plotting and parameter storing
    pip install matplotlib pandas

Usage

See the example directory for a full usage example, estimating the Holzinger-Swineford model using maximum likelihood, unweighted least squares, and diagonally weighted least squares.

tensorsem's People

Contributors

vankesteren avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.