sPyNNaker neural_modelling  7.4.2
weight_multiplicative_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 The University of Manchester
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
19 #ifndef _WEIGHT_MULTIPLICATIVE_IMPL_H_
20 #define _WEIGHT_MULTIPLICATIVE_IMPL_H_
21 
22 // Include generic plasticity maths functions
25 #include <neuron/synapse_row.h>
26 
27 #include <debug.h>
28 
29 //---------------------------------------
30 // Structures
31 //---------------------------------------
33 typedef struct {
34  accum min_weight;
35  accum max_weight;
36 
37  accum a2_plus;
38  accum a2_minus;
40 
42 typedef struct {
43  accum weight;
44 
46  uint32_t weight_shift;
48  const plasticity_weight_region_data_t *weight_region;
50 
51 #include "weight_one_term.h"
52 
53 //---------------------------------------
54 // Weight dependance functions
55 //---------------------------------------
63  weight_t weight, index_t synapse_type) {
65  extern uint32_t *weight_shift;
66 
67  accum s1615_weight = kbits(weight << weight_shift[synapse_type]);
68  return (weight_state_t) {
69  .weight = s1615_weight,
70  .weight_shift = weight_shift[synapse_type],
71  .weight_region = &plasticity_weight_region_data[synapse_type]
72  };
73 }
74 
75 //---------------------------------------
81  weight_state_t state, int32_t depression) {
82  // Calculate scale
83  accum scale = (state.weight - state.weight_region->min_weight) *
84  state.weight_region->a2_minus;
85 
86  // Multiply scale by depression and subtract
87  state.weight -= mul_accum_fixed(scale, depression);
88  return state;
89 }
90 //---------------------------------------
96  weight_state_t state, int32_t potentiation) {
97  // Calculate scale
98  accum scale = (state.weight_region->max_weight - state.weight) *
99  state.weight_region->a2_plus;
100 
101  // Multiply scale by potentiation and add
102  // **NOTE** using standard STDP fixed-point format handles format conversion
103  state.weight += mul_accum_fixed(scale, potentiation);
104  return state;
105 }
106 //---------------------------------------
112 static inline weight_t weight_get_final(weight_state_t state) {
113  return (weight_t) (bitsk(state.weight) >> state.weight_shift);
114 }
115 
116 static inline void weight_decay(weight_state_t *state, int32_t decay) {
117  state->weight = mul_accum_fixed(state->weight, decay);
118 }
119 
120 static inline accum weight_get_update(weight_state_t state) {
121  return state.weight;
122 }
123 
124 #endif // _WEIGHT_MULTIPLICATIVE_IMPL_H_
#define decay(x, d)
This is a type-generic decay "function".
Definition: decay.h:118
Support functions for STDP.
Basic definitions for STDP.
static accum mul_accum_fixed(accum a, int32_t stdp_fixed)
Multiply an accum by an STDP fixed point and return an accum.
Definition: stdp_typedefs.h:45
implementation for handling the processing of synapse rows.
static void weight_decay(weight_state_t *state, int32_t decay)
Decay the weight inside the state by multiplication.
static accum weight_get_update(weight_state_t state)
Get the weight inside during update in STDP fixed point format.
uint32_t * weight_shift
Plasticity multiply shift array, in DTCM.
plasticity_weight_region_data_t * plasticity_weight_region_data
Global plasticity parameter data.
const plasticity_weight_region_data_t * weight_region
Reference to the configuration data.
static weight_state_t weight_one_term_apply_potentiation(weight_state_t state, int32_t potentiation)
Apply the potentiation rule to the weight state.
accum a2_plus
Scaling factor for weight delta on potentiation.
static weight_state_t weight_get_initial(weight_t weight, index_t synapse_type)
Gets the initial weight state.
accum a2_minus
Scaling factor for weight delta on depression.
static weight_state_t weight_one_term_apply_depression(weight_state_t state, int32_t depression)
Apply the depression rule to the weight state.
static weight_t weight_get_final(weight_state_t state)
Gets the final weight.
accum weight
The starting weight.
uint32_t weight_shift
Weight shift to S1615 version.
The current state data for the rule.
API for single-term weight dependence rules.