Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# from psyneulink.globals.Run import run, construct_inputs
Input_Layer = TransferMechanism(name='Input Layer',
function=Logistic(),
default_variable = np.zeros((2,)))
Hidden_Layer_1 = TransferMechanism(name='Hidden Layer_1',
function=Logistic(),
default_variable = np.zeros((5,)))
Hidden_Layer_2 = TransferMechanism(name='Hidden Layer_2',
function=Logistic(),
default_variable = [0,0,0,0])
Output_Layer = TransferMechanism(name='Output Layer',
function=Logistic(),
default_variable = [0,0,0])
random_weight_matrix = lambda sender, receiver : random_matrix(sender, receiver, .2, -.1)
Input_Weights_matrix = (np.arange(2*5).reshape((2, 5)) + 1)/(2*5)
Middle_Weights_matrix = (np.arange(5*4).reshape((5, 4)) + 1)/(5*4)
Output_Weights_matrix = (np.arange(4*3).reshape((4, 3)) + 1)/(4*3)
# TEST PROCESS.LEARNING WITH:
# CREATION OF FREE STANDING PROJECTIONS THAT HAVE NO LEARNING (Input_Weights, Middle_Weights and Output_Weights)
# INLINE CREATION OF PROJECTIONS (Input_Weights, Middle_Weights and Output_Weights)
# NO EXPLICIT CREATION OF PROJECTIONS (Input_Weights, Middle_Weights and Output_Weights)
# This projection will be used by the process below by referencing it in the process' pathway;
from psyneulink.components.functions.Function import FHNIntegrator
from psyneulink.components.mechanisms.ProcessingMechanisms.TransferMechanism import TransferMechanism
from psyneulink.components.Process import process
from psyneulink.components.System import system
from PsyNeuLink.Library.Subsystems.AGT.AGTControlMechanism import AGTControlMechanism
from PsyNeuLink.Library.Subsystems.AGT.LCControlMechanism import LCControlMechanism
decision_mech = TransferMechanism(name='Decision_Mech')
# my_AGT = AGTControlMechanism(monitored_output_states=decision_mech,)
# my_LC = LCControlMechanism(function=(FHNIntegrator(mode=(1.0, my_AGT))),
# objective_mechanism=[decision_mech])
my_LC = LCControlMechanism(objective_mechanism=[decision_mech],
modulated_mechanisms=[decision_mech],
name='LC')
my_AGT = AGTControlMechanism(monitored_output_states=decision_mech,
control_signals=(FHNIntegrator.MODE,my_LC),
name='ITC')
my_main_process = process(pathway=[decision_mech], name='Decision_process')
my_AGT_process = process(pathway=[decision_mech, my_AGT], name='AGT_process')
my_LC_process = process(pathway=[decision_mech, my_LC], name='LC_process')
process_b = process(pathway=[my_mech_B])
my_system = system(processes=[process_a, process_b],
monitor_for_control=[my_mech_A.output_states[RESULT],
my_mech_B.output_states[MEAN]],
control_signals=[(GAIN, my_mech_A), {NAME: INTERCEPT,
MECHANISM:
my_mech_B,
MODULATION:
ModulationParam.ADDITIVE}],
name='My Test System')
# endregion
# region GatingSignal
my_mechanism_a = TransferMechanism()
my_mechanism_b = TransferMechanism()
my_gating_mechanism = GatingMechanism(
gating_signals=[my_mechanism_a, my_mechanism_b.output_state])
my_input_layer = TransferMechanism(size=3)
my_hidden_layer = TransferMechanism(size=5)
my_output_layer = TransferMechanism(size=2)
my_gating_mechanism = GatingMechanism(gating_signals=[
{'GATE_ALL': [my_input_layer, my_hidden_layer, my_output_layer]}],
modulation=ModulationParam.ADDITIVE)
# Should this be list or tuple?
my_gating_mechanism = GatingMechanism(gating_signals=[
{NAME: 'GATING_SIGNAL_A', GATE: my_input_layer,
MODULATION: ModulationParam.ADDITIVE},
{NAME: 'GATING_SIGNAL_B', GATE: [my_hidden_layer, my_output_layer]}])
# endregion
def mechanisms():
# Creating a mechanism
my_mech = TransferMechanism(input_states=['MY_INPUT'],
output_states=[RESULT, MEAN, VARIANCE])
# Structure
# Function
my_mechanism = TransferMechanism(function=Logistic(gain=1.0, bias=-4))
# region TransferMechanism
my_linear_transfer_mechanism = TransferMechanism(function=Linear)
my_logistic_transfer_mechanism = TransferMechanism(
function=Logistic(gain=1.0, bias=-4))
# class arguments section doesn't word wrap
# endregion
# region IntegratorMechanism
my_time_averaging_mechanism = IntegratorMechanism(
function=AdaptiveIntegrator(rate=0.5))
# endregion
# region DDM
# Structure
my_DDM = DDM(function=BogaczEtAl)
from psyneulink.components.functions.Function import Logistic
from psyneulink.components.mechanisms.ProcessingMechanisms.TransferMechanism import TransferMechanism
from psyneulink.components.Process import process
from psyneulink.components.Projections.PathwayProjections.MappingProjection import MappingProjection
Input_Layer = TransferMechanism(name='Input Layer',
function=Logistic(),
default_variable = [0,0])
Hidden_Layer_1 = TransferMechanism(name='Hidden Layer_1',
function=Logistic(),
default_variable = [0,0,0,0,0])
Output_Layer = DDM(name='Output Layer DDM',
threshold=0.1,
params = {MONITOR_FOR_LEARNING:PROBABILITY_LOWER_THRESHOLD},
default_variable = [0])
Input_Weights = MappingProjection(name='Input Weights',
sender=Input_Layer,
receiver=Hidden_Layer_1,
# params={FUNCTION_PARAMS:{MATRIX:(IDENTITY_MATRIX,CONTROL_PROJECTION)}}
NOutputUnits = NOutputDimensions #* NFeatures
NHiddenUnits = NInputDimensions * NOutputDimensions # * NInputDimensions #* NFeatures
NTaskUnits = NInputDimensions #NInputDimensions * NOutputDimensions
# MECHANISMS
Stimulus_Layer = TransferMechanism(name='Stimulus Layer',
function=Linear(),
default_variable = np.zeros((NInputUnits,)))
Task_Layer = TransferMechanism(name='Task Layer',
function=Linear(),
default_variable = np.zeros((NTaskUnits,)))
Hidden_Layer = TransferMechanism(name='Hidden Layer',
function=Logistic(),
default_variable = np.zeros((NHiddenUnits,)))
Output_Layer = TransferMechanism(name='Output Layer',
function=Logistic(),
default_variable = np.zeros((NOutputUnits,)))
# WEIGHT MATRICES
Stimulus_Hidden_Weights_Matrix = np.random.uniform(0, 0.1, (NInputUnits, NHiddenUnits))
Hidden_Output_Weights_Matrix = np.random.uniform(0, 0.1, (NHiddenUnits, NOutputUnits))
Task_Hidden_Weights_Matrix = np.random.uniform(0, 0.1, (NTaskUnits, NHiddenUnits))
# MAPPING PROJECTIONS
# name='My_DDM_2'
# )
#
# myMechanism_3 = DDM(params={FUNCTION_PARAMS:{DRIFT_RATE:3.0,
# THRESHOLD:30.0},
# kwDDM_AnalyticSolution:kwBogaczEtAl},
# prefs = DDM_prefs,
# name='My_DDM_3'
# )
#
# process_prefs = ComponentPreferenceSet(reportOutput_pref=PreferenceEntry(True,PreferenceLevel.INSTANCE),
# verbose_pref=PreferenceEntry(True,PreferenceLevel.INSTANCE))
#
# process_prefs.show()
Layer_1 = TransferMechanism(default_variable=[0,0], name='Layer 1')
Layer_2 = TransferMechanism(default_variable=[0,0], name='Layer 2')
Layer_3 = TransferMechanism(default_variable=[0,0], name='Layer 3')
myProcess_1 = Process_Base(default_variable=[0, 0],
params={PATHWAY:[(Layer_1, 0),
IDENTITY_MATRIX,
(Layer_3, 0)]})
myProcess_2 = Process_Base(default_variable=[0, 0],
params={PATHWAY:[(Layer_2, 0),
FULL_CONNECTIVITY_MATRIX,
(Layer_3, 0)]})
mySystem = System_Base(params={PROCESSES:[(myProcess_1,0), (myProcess_2,0)]})
def scheduler():
# basic phasing in a linear process
A = TransferMechanism(function=Linear(), name='A')
B = TransferMechanism(function=Linear(), name='B')
C = TransferMechanism(function=Linear(), name='C')
# p = process(pathway=[A, B, C], name='p')
# s = system(processes=[p], name='s')
#
# sched = Scheduler(system=s)
# sched.add_condition(B, EveryNCalls(A, 2))
# sched.add_condition(C, EveryNCalls(B, 3))
#
# output = list(sched.run())
# print(output)
# alternate basic phasing in a linear process
# p = process(pathway=[A, B], name='p')
# s = system(processes=[p], name='s')
# coding: utf-8
# In[ ]:
from psyneulink.components.mechanisms.ProcessingMechanisms.TransferMechanism import TransferMechanism
from psyneulink.components.Process import process
from psyneulink.components.Projections.PathwayProjections.MappingProjection import MappingProjection
from psyneulink.components.System import system
#The following code starts to build a 3 layer neural network
input_layer = TransferMechanism(name='Input Layer',
function=Logistic,
default_variable = np.zeros((2,)))
hidden_layer = TransferMechanism(name='Hidden Layer',
function = Linear,
default_variable =[0])
output_layer = TransferMechanism(name='Output Layer',
function=Linear,
default_variable =[0])
input_hidden_weights = MappingProjection(name='Input-Hidden Weights',
matrix = np.random.rand(2,1)*1 - .5)
from psyneulink.components.Projections.PathwayProjections.MappingProjection import MappingProjection
from psyneulink.components.System import *
from psyneulink.globals.Keywords import *
from psyneulink.globals.preferences.ComponentPreferenceSet import REPORT_OUTPUT_PREF, VERBOSE_PREF
process_prefs = {REPORT_OUTPUT_PREF: True,
VERBOSE_PREF: False}
system_prefs = {REPORT_OUTPUT_PREF: True,
VERBOSE_PREF: False}
colors = TransferMechanism(default_variable=[0,0],
function=Linear,
name="Colors")
words = TransferMechanism(default_variable=[0,0],
function=Linear,
name="Words")
hidden = TransferMechanism(default_variable=[0,0],
function=Logistic,
name="Hidden")
response = TransferMechanism(default_variable=[0,0],
function=Logistic(),
name="Response")
output = TransferMechanism(default_variable=[0,0],
function=Logistic,
name="Output")
CH_Weights_matrix = np.arange(4).reshape((2,2))