Giter Club home page Giter Club logo

Comments (5)

satunheim avatar satunheim commented on May 29, 2024

The “set_weight” method is already available. Sorry I hadn't noticed.

from tmu.

satunheim avatar satunheim commented on May 29, 2024

The set_TA_action and set_weight methods work fine. However, it seems one has to perform training of the TM (in my case the TMCoalescedClassifier) before the methods can be applied. This is possibly difficult to avoid. If that is the case, one can perform only a short training phase (with only a few samples) only to get all the clause_banks etc. defined, before one "loads" an existing model to the TM.

from tmu.

perara avatar perara commented on May 29, 2024

Currently, we need to run .fit before the model is initialized.
But we might be able to do the following, if @olegranmo:
Perhaps we should make a parameter: input_shape in the constructor of TM models. then we can initialize models before fit is executed.

What do you think?

from tmu.

olegranmo avatar olegranmo commented on May 29, 2024

It absolutely makes sense to add shape. What is extracted from the data is simply the number of features and the number of classes, which is needed to set up the data structures

from tmu.

satunheim avatar satunheim commented on May 29, 2024

The following code example seems to work well back and forth, and utilizes .csv model files. Here I do not use the TA_action_data when loading a model, just the TA_state_data. I am sure there can be more elegant ways to implement things, but this is something that is easy to understand and use.

If a model can be loaded without performing the fit method first, this can be time saving for various experiments.

####################################################
#EXTRACT a model from a trained TM (TMCoalescedClassifier):
####################################################

numberofclasses = 10
numberofclauses = 128
numberofliterals=272

TA_action_array= np.zeros((numberofclauses, numberofliterals), int)
TA_state_array= np.zeros((numberofclauses, numberofliterals), int)

for k in range (numberofclauses):
for b in range (numberofliterals):
TA_state_array[k,b]= tm.get_ta_state(k,b)
if tm.get_ta_action(k,b) == True:
TA_action_array[k,b]=1

weightarray=np.zeros((numberofclasses, numberofclauses), int)
for g in range (numberofclasses):
for c in range (numberofclauses):
weightarray[g,c]=tm.get_weight(g,c)

#SAVE MODEL:
savetxt('TA_action_data.csv', TA_action_array, delimiter=',')
savetxt('TA_state_data.csv', TA_state_array, delimiter=',')
savetxt('weight_data.csv', weightarray, delimiter=',')

#LOAD MODEL:
weightarray = loadtxt('weight_data.csv', delimiter=',')
#TA_action_array = loadtxt('TA_action_data.csv', delimiter=',')
TA_state_array = loadtxt('TA_state_data.csv', delimiter=',')

for k in range (numberofclauses):
for b in range (numberofliterals):
tm.set_ta_state(k, b, int(TA_state_array[k,b]))

for g in range (numberofclasses):
for c in range (numberofclauses):
tm.set_weight(g, c, Weightarray[g,c])

from tmu.

Related Issues (20)

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.