Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3129

Merged
merged 44 commits into from
Dec 5, 2024
Merged

Devel #3129

Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
edf7389
requirements: update optuna requirement from <4.1.0 to <4.2.0 (#3110)
dependabot[bot] Nov 13, 2024
c70ee2a
test/EMComposition: Split softmax_choice test
jvesely Nov 9, 2024
ced7935
Functions/OneHot: Fix "DETERMINISITC" typo
jvesely Nov 11, 2024
3053b0c
Functions/OneHot: Use local PRNG to randomly select extreme index
jvesely Nov 9, 2024
59c9736
llvm/Mechanism: Reinit integrator_function in Mechanism reset if pres…
jvesely Nov 14, 2024
3fc73e1
Parameter: correct .set post-initialization check (#3116)
kmantel Nov 14, 2024
ee61d35
Fix/matrix transform l0 (#3113)
jdcpni Nov 14, 2024
7542b75
broken_trans_deps: Block coverage==7.6.5 (#3118)
jvesely Nov 15, 2024
67e6d0e
Feat/emcomposition/assign field weights (#3117)
jdcpni Nov 15, 2024
0e1dbae
fix/standard_output_ports_calculate (#3114)
jdcpni Nov 15, 2024
0b085b5
Mechanism: if any port has default_input, get variable from input_ports
kmantel Nov 15, 2024
06d9eee
Port: use default_input before checking projections
kmantel Nov 12, 2024
cbe6c02
Prioritize Port.default_input over projection values and default vari…
kmantel Nov 16, 2024
272f3d1
requirements: update grpcio requirement from <1.68.0 to <1.69.0 (#3120)
dependabot[bot] Nov 19, 2024
a60f94b
tests/OneHot: Add mode=DETERMINISTIC tests
jvesely Nov 11, 2024
ccd7f67
llvm/OneHot: Isolate handling of PROB and PROB_INDICATOR modes
jvesely Nov 12, 2024
09286c7
llvm/OneHot: Refactor to match Python behaviour for modes != DETERMIN…
jvesely Nov 12, 2024
a8d679a
llvm/DictionaryMemory: Remove OneHot mode workarounds
jvesely Nov 17, 2024
0a4e94c
llvm: Convert recursive array iterator into contextmanager
jvesely Nov 20, 2024
237af5f
llvm/Component: Allow 'indicator' and 'abs_val' parameters in OneHot …
jvesely Nov 20, 2024
cd9ecee
llvm/OneHot: Add basic implementation of DETERMINISTIC mode
jvesely Nov 20, 2024
a2cb5ae
tests/llvm: Test more int32 samples in MT builtin test
jvesely Nov 13, 2024
014ca35
llvm: Implement range integer generation to match Numpy's
jvesely Nov 13, 2024
157d139
llvm: Implement range integer generation to match old Numpy's
jvesely Nov 13, 2024
443c6e1
llvm/OneHot: Implement support for RANDOM tie resolution
jvesely Nov 20, 2024
8822de0
Component: make deprecated arg error via illegal args; deprecate 'siz…
kmantel Nov 21, 2024
16f961b
Merge remote-tracking branch 'origin/devel' into devel
jvesely Nov 21, 2024
735890d
llvm/OneHot: Simplify PROB/PROB_INDICATOR implementation
jvesely Nov 21, 2024
06bff2b
tests/llvm/random: Use array_equal to test integer results
jvesely Nov 21, 2024
c0f73e2
llvm/OneHot: Implement all modes (#3124)
jvesely Nov 21, 2024
ad1e743
refactor/emcomposition_field_handling (#3122)
jdcpni Nov 22, 2024
bf1e6b3
patch/autodiff_pnl_showgraph (#3125)
jdcpni Nov 22, 2024
7b20f13
Refactor/emcomposition/fields class (#3126)
jdcpni Nov 25, 2024
5c9f60a
patch/emcomposition/field_memory_indices (#3127)
jdcpni Nov 25, 2024
ad37a11
patch/emcomposition/field_memories (#3128)
jdcpni Nov 26, 2024
06c5a65
ci: test-release: add matrix.dist to test result artifact
kmantel Nov 26, 2024
f3c01d9
ci: test-release: exclude macos-11 on py3.7
kmantel Nov 26, 2024
62344a2
ci: release workflow minor corrections (#3130)
kmantel Nov 26, 2024
e1a5bd0
Fix/add obj mech warning (#3131)
jdcpni Nov 26, 2024
f91e2a1
ci/ga: Use console_output_style=count (#3132)
jvesely Nov 26, 2024
8d2fafc
fix/lccontrolmechanism_objectivemechanism (#3134)
jdcpni Nov 28, 2024
cd06c82
requirements: update pytest-profiling requirement from <1.8.1 to <1.8…
dependabot[bot] Nov 30, 2024
9ffdc58
Feat/composition reset clear results (#3136)
jdcpni Dec 2, 2024
ff4a3e6
requirements: update pytest requirement from <8.3.4 to <8.3.5 (#3138)
dependabot[bot] Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ def calc_prob(em_preds, test_ys):

# Names:
name = "EGO Model CSW",
em_name = "EM",
state_input_layer_name = "STATE",
previous_state_layer_name = "PREVIOUS STATE",
context_layer_name = 'CONTEXT',
em_name = "EM",
prediction_layer_name = "PREDICTION",

# Structural
state_d = 11, # length of state vector
previous_state_d = 11, # length of state vector
context_d = 11, # length of context vector
memory_capacity = ALL, # number of entries in EM memory; ALL=> match to number of stims
# memory_init = (0,.0001), # Initialize memory with random values in interval
memory_init = None, # Initialize with zeros
concatenate_queries = False,
# concatenate_queries = True,
memory_init = (0,.0001), # Initialize memory with random values in interval
# memory_init = None, # Initialize with zeros
# concatenate_queries = False,
concatenate_queries = True,

# environment
# curriculum_type = 'Interleaved',
Expand All @@ -63,20 +63,23 @@ def calc_prob(em_preds, test_ys):

# Processing
integration_rate = .69, # rate at which state is integrated into new context
# state_weight = 1, # weight of the state used during memory retrieval
# state_weight =normalize_field_weightsnormalize_field_weights 1, # weight of the state used during memory retrieval
# context_weight = 1, # weight of the context used during memory retrieval
state_weight = .5, # weight of the state used during memory retrieval
previous_state_weight = .5, # weight of the state used during memory retrieval
context_weight = .5, # weight of the context used during memory retrieval
state_weight = None, # weight of the state used during memory retrieval
# normalize_field_weights = False, # whether to normalize the field weights during memory retrieval
normalize_field_weights = True, # whether to normalize the field weights during memory retrieval
normalize_memories = False, # whether to normalize the memory during memory retrieval
# normalize_memories = True, # whether to normalize the memory during memory retrieval
# softmax_temperature = None, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
softmax_temperature = .1, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_temperature = ADAPTIVE, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_temperature = CONTROL, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_threshold = None, # threshold used to mask out small values in softmax
softmax_threshold = .001, # threshold used to mask out small values in softmax
enable_learning=[False, False, True], # Enable learning for PREDICTION (STATE) but not CONTEXT or PREVIOUS STATE
learn_field_weights = False,
# target_fields=[True, False, False], # Enable learning for PREDICTION (STATE) but not CONTEXT or PREVIOUS STATE
enable_learning = True,
loss_spec = Loss.BINARY_CROSS_ENTROPY,
# loss_spec = Loss.MSE,
learning_rate = .5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
'CONTEXT',
'PREVIOUS STATE'],
start=0)
state_retrieval_weight = 0
state_retrieval_weight = None
RANDOM_WEIGHTS_INITIALIZATION=RandomMatrix(center=0.0, range=0.1) # Matrix spec used to initialize all Projections

if is_numeric_scalar(model_params['softmax_temperature']): # translate to gain of softmax retrieval function
Expand All @@ -194,7 +194,7 @@ def construct_model(model_name:str=model_params['name'],
state_size:int=model_params['state_d'],

# Previous state
previous_state_input_name:str=model_params['previous_state_layer_name'],
previous_state_name:str=model_params['previous_state_layer_name'],

# Context representation (learned):
context_name:str=model_params['context_layer_name'],
Expand All @@ -205,12 +205,15 @@ def construct_model(model_name:str=model_params['name'],
em_name:str=model_params['em_name'],
retrieval_softmax_gain=retrieval_softmax_gain,
retrieval_softmax_threshold=model_params['softmax_threshold'],
state_retrieval_weight:Union[float,int]=state_retrieval_weight,
previous_state_retrieval_weight:Union[float,int]=model_params['state_weight'],
# state_retrieval_weight:Union[float,int]=state_retrieval_weight,
# previous_state_retrieval_weight:Union[float,int]=model_params['state_weight'],
state_retrieval_weight:Union[float,int]=model_params['state_weight'],
previous_state_retrieval_weight:Union[float,int]=model_params['previous_state_weight'],
context_retrieval_weight:Union[float,int]=model_params['context_weight'],
normalize_field_weights = model_params['normalize_field_weights'],
normalize_memories = model_params['normalize_memories'],
concatenate_queries = model_params['concatenate_queries'],
learn_field_weights = model_params['learn_field_weights'],
enable_learning = model_params['enable_learning'],
memory_capacity = memory_capacity,
memory_init=model_params['memory_init'],

Expand All @@ -219,7 +222,7 @@ def construct_model(model_name:str=model_params['name'],

# Learning
loss_spec=model_params['loss_spec'],
enable_learning=model_params['enable_learning'],
# target_fields=model_params['target_fields'],
learning_rate = model_params['learning_rate'],
device=model_params['device']

Expand All @@ -233,23 +236,35 @@ def construct_model(model_name:str=model_params['name'],
# ----------------------------------------------------------------------------------------------------------------

state_input_layer = ProcessingMechanism(name=state_input_name, input_shapes=state_size)
previous_state_layer = ProcessingMechanism(name=previous_state_input_name, input_shapes=state_size)
previous_state_layer = ProcessingMechanism(name=previous_state_name, input_shapes=state_size)
# context_layer = ProcessingMechanism(name=context_name, input_shapes=context_size)
context_layer = TransferMechanism(name=context_name,
input_shapes=context_size,
function=Tanh,
integrator_mode=True,
integration_rate=integration_rate)



em = EMComposition(name=em_name,
memory_template=[[0] * state_size, # state
[0] * state_size, # previous state
[0] * state_size], # context
memory_fill=memory_init,
memory_capacity=memory_capacity,
normalize_memories=False,
memory_decay_rate=0,
softmax_gain=retrieval_softmax_gain,
softmax_threshold=retrieval_softmax_threshold,
fields = {state_input_name: {FIELD_WEIGHT: state_retrieval_weight,
LEARN_FIELD_WEIGHT: False,
TARGET_FIELD: True},
previous_state_name: {FIELD_WEIGHT:previous_state_retrieval_weight,
LEARN_FIELD_WEIGHT: False,
TARGET_FIELD: False},
context_name: {FIELD_WEIGHT:context_retrieval_weight,
LEARN_FIELD_WEIGHT: False,
TARGET_FIELD: False}},
# Input Nodes:
# field_names=[state_input_name,
# previous_state_input_name,
Expand All @@ -259,19 +274,20 @@ def construct_model(model_name:str=model_params['name'],
# previous_state_retrieval_weight,
# context_retrieval_weight
# ),
field_names=[previous_state_input_name,
context_name,
state_input_name,
],
field_weights=(previous_state_retrieval_weight,
context_retrieval_weight,
state_retrieval_weight,
),
# field_names=[previous_state_input_name,
# context_name,
# state_input_name,
# ],
# field_weights=(previous_state_retrieval_weight,
# context_retrieval_weight,
# state_retrieval_weight,
# ),
normalize_field_weights=normalize_field_weights,
normalize_memories=normalize_memories,
concatenate_queries=concatenate_queries,
learn_field_weights=learn_field_weights,
learning_rate=learning_rate,
enable_learning=enable_learning,
learning_rate=learning_rate,
# target_fields=target_fields,
device=device
)

Expand Down Expand Up @@ -311,7 +327,7 @@ def construct_model(model_name:str=model_params['name'],
em]
previous_state_to_em_pathway = [previous_state_layer,
MappingProjection(sender=previous_state_layer,
receiver=em.nodes[previous_state_input_name+QUERY],
receiver=em.nodes[previous_state_name+QUERY],
matrix=IDENTITY_MATRIX,
learnable=False),
em]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import numpy as np
import torch
from torch.utils.data import dataset
from random import randint

def one_hot_encode(labels, num_classes):
"""
One hot encode labels and convert to tensor.
"""
return torch.tensor((np.arange(num_classes) == labels[..., None]).astype(float),dtype=torch.float32)

class DeterministicCSWDataset(dataset.Dataset):
def __init__(self, n_samples_per_context, contexts_to_load) -> None:
super().__init__()
raw_xs = np.array([
[[9,1,3,5,7],[9,2,4,6,8]],
[[10,1,4,5,8],[10,2,3,6,7]]
])

item_indices = np.random.choice(raw_xs.shape[1],sum(n_samples_per_context),replace=True)
task_names = [0,1] # Flexible so these can be renamed later
task_indices = [task_names.index(name) for name in contexts_to_load]

context_indices = np.repeat(np.array(task_indices),n_samples_per_context)
self.xs = one_hot_encode(raw_xs[context_indices,item_indices],11)

self.xs = self.xs.reshape((-1,11))
self.ys = torch.cat([self.xs[1:],one_hot_encode(np.array([0]),11)],dim=0)
context_indices = np.repeat(np.array(task_indices),[x*5 for x in n_samples_per_context])
self.contexts = one_hot_encode(context_indices, len(task_names))

# Remove the last transition since there's no next state available
self.xs = self.xs[:-1]
self.ys = self.ys[:-1]
self.contexts = self.contexts[:-1]

def __len__(self):
return len(self.xs)

def __getitem__(self, idx):
return self.xs[idx], self.contexts[idx], self.ys[idx]

def generate_dataset(condition='Blocked'):
# Generate the dataset for either the blocked or interleaved condition
if condition=='Blocked':
contexts_to_load = [0,1,0,1] + [randint(0,1) for _ in range(40)]
n_samples_per_context = [40,40,40,40] + [1]*40
elif condition == 'Interleaved':
contexts_to_load = [0,1]*80 + [randint(0,1) for _ in range(40)]
n_samples_per_context = [1]*160 + [1]*40
else:
raise ValueError(f'Unknown dataset condition: {condition}')

return DeterministicCSWDataset(n_samples_per_context, contexts_to_load)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

# Settings for running script:

MODEL_PARAMS = 'TestParams'
# MODEL_PARAMS = 'DeclanParams'
# MODEL_PARAMS = 'TestParams'
MODEL_PARAMS = 'DeclanParams'

CONSTRUCT_MODEL = True # THIS MUST BE SET TO True to run the script
DISPLAY_MODEL = ( # Only one of the following can be uncommented:
Expand All @@ -13,7 +13,7 @@
# # 'show_pytorch': True, # show pytorch graph of model
# 'show_learning': True,
# # 'show_nested_args': {'show_learning': pnl.ALL},
# 'show_projections_not_in_composition': True,
# # 'show_projections_not_in_composition': True,
# # 'show_nested': {'show_node_structure': True},
# # 'exclude_from_gradient_calc_style': 'dashed'# show target mechanisms for learning
# # 'show_node_structure': True # show detailed view of node structures and projections
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from psyneulink.core.llvm import ExecutionMode
from psyneulink.core.globals.keywords import ALL, ADAPTIVE, CONTROL, CPU, Loss, MPS, OPTIMIZATION_STEP, RUN, TRIAL



model_params = dict(

# Names:
name = "EGO Model CSW",
em_name = "EM",
state_input_layer_name = "STATE",
previous_state_layer_name = "PREVIOUS STATE",
context_layer_name = 'CONTEXT',
em_name = "EM",
prediction_layer_name = "PREDICTION",

# Structural
Expand All @@ -20,7 +22,6 @@
# memory_init = None, # Initialize with zeros
concatenate_queries = False,
# concatenate_queries = True,

# environment
# curriculum_type = 'Interleaved',
curriculum_type = 'Blocked',
Expand All @@ -33,18 +34,19 @@
context_weight = 1, # weight of the context used during memory retrieval
# normalize_field_weights = False, # whether to normalize the field weights during memory retrieval
normalize_field_weights = True, # whether to normalize the field weights during memory retrieval
normalize_memories = False, # whether to normalize the memory during memory retrieval
# softmax_temperature = None, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
softmax_temperature = .1, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_temperature = ADAPTIVE, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_temperature = CONTROL, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_threshold = None, # threshold used to mask out small values in softmax
softmax_threshold = .001, # threshold used to mask out small values in softmax
enable_learning=[True, False, False], # Enable learning for PREDICTION (STATE) but not CONTEXT or PREVIOUS STATE
# enable_learning=[True, True, True]
# enable_learning=True,
# enable_learning=False,
learn_field_weights = True,
# learn_field_weights = False,
# target_fields=[True, False, False], # Enable learning for PREDICTION (STATE) but not CONTEXT or PREVIOUS STATE
# target_fields=[True, True, True]
# target_fields=True,
# target_fields=False,
enable_learning = True,
# enable_learning = False,
loss_spec = Loss.BINARY_CROSS_ENTROPY,
# loss_spec = Loss.CROSS_ENTROPY,
# loss_spec = Loss.MSE,
Expand All @@ -53,8 +55,8 @@
synch_weights = RUN,
synch_values = RUN,
synch_results = RUN,
execution_mode = ExecutionMode.Python,
# execution_mode = ExecutionMode.PyTorch,
# execution_mode = ExecutionMode.Python,
execution_mode = ExecutionMode.PyTorch,
device = CPU,
# device = MPS,
)
Expand Down
4 changes: 4 additions & 0 deletions broken_trans_deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ cattrs != 23.2.1, != 23.2.2
# https://github.com/beartype/beartype/issues/324
beartype != 0.17.1; python_version == '3.9'

# coverage 7.6.5 is broken
# https://github.com/nedbat/coveragepy/issues/1891
coverage != 7.6.5

# The following need at least sphinx-5 without indicating it in dependencies:
# * sphinxcontrib-applehelp >=1.0.8,
# * sphinxcontrib-devhelp >=1.0.6,
Expand Down
11 changes: 0 additions & 11 deletions docs/source/CombinationFunctions.rst

This file was deleted.

4 changes: 2 additions & 2 deletions docs/source/Core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ Core

- `NonStatefulFunctions`

- `CombinationFunctions`

- `DistributionFunctions`

- `LearningFunctions`
Expand All @@ -71,6 +69,8 @@ Core

- `TransferFunctions`

- `TransformFunctions`

- `StatefulFunctions`

- `IntegratorFunctions`
Expand Down
5 changes: 3 additions & 2 deletions docs/source/NonStatefulFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Functions that do *not* depend on a previous value.
.. toctree::
:maxdepth: 1

CombinationFunctions

DistributionFunctions
LearningFunctions
ObjectiveFunctions
OptimizationFunctions
SelectionFunctions
TransferFunctions
TransferFunctions
TransformFunctions
11 changes: 11 additions & 0 deletions docs/source/TransformFunctions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TransformFunctions
==================

.. toctree::
:maxdepth: 3

.. automodule:: psyneulink.core.components.functions.transformfunctions
:members: Concatenate, Rearrange, Reduce, LinearCombination, CombineMeans, MatrixTransform, PredictionErrorDeltaFunction
:private-members:
:exclude-members: Parameters

Loading
Loading