├── Characterise Quality ├── assessDBonTasks.m ├── runCHARC.m └── runCHARC_parallel.m ├── Evolve to Task ├── Multi objective │ └── nsga2.m └── Single objective │ ├── MAPeliteFcn.m │ ├── MAPelites.m │ └── MicrobialGA.m ├── LICENSE ├── README.md └── Support files ├── Simulators └── robot-sim │ └── mars_install │ ├── Addons │ ├── Map │ │ ├── Map_Initialize.m │ │ ├── Map_Loop.m │ │ ├── Map_Plot.m │ │ └── Map_Plot_Initialize.m │ ├── Peg │ │ ├── Peg_Initialize.m │ │ ├── Peg_Loop.m │ │ └── Peg_Plot_Initialize.m │ └── Voronoi │ │ ├── Voronoi_Loop.m │ │ ├── Voronoi_Plot.m │ │ ├── Voronoi_Plot_Initialize.m │ │ └── todo.txt │ ├── Demos │ ├── Demo_Circle.m │ ├── Demo_Holonomic.m │ ├── Demo_Obstacles.m │ ├── Demo_Obstacles_Sensor.m │ ├── Demo_Open_Space.m │ ├── Demo_Peg.m │ ├── Demo_Sensor.m │ ├── Demo_Square.m │ ├── Demo_Unbounded.m │ └── Demo_Voronoi.m │ ├── MARS.rtf │ ├── Resources │ ├── Check_Obs_collision.m │ ├── Check_bounds.m │ ├── Check_collision.m │ ├── Sensors │ │ ├── Add_sensor.m │ │ ├── Load_sensors.m │ │ ├── Manage_sensors.m │ │ ├── ProximitySensor_compute.m │ │ ├── ProximitySensor_plot.m │ │ ├── RangeFinderIdeal_compute.m │ │ ├── RangeFinderIdeal_plot.m │ │ ├── RangeFinder_compute.asv │ │ ├── RangeFinder_compute.m │ │ └── RangeFinder_plot.m │ ├── move_to.m │ ├── p_poly_dist.m │ └── wrapToPi.m │ ├── Tasks │ ├── explore_behaviour.m │ ├── explore_maze.m │ └── follow_behaviour.m │ ├── mars.m │ └── robotSim.m ├── other ├── Activations │ ├── LeakyReLU.m │ ├── RBF.m │ ├── ReLU.m │ ├── binary.m │ ├── eLU.m │ ├── findActiv.m │ ├── gaussDist.m │ ├── linearNode.m │ ├── logistic.m │ ├── mackeyGlassNode.m │ ├── paraReLU.m │ ├── sawtooth.m │ ├── sin2.m │ ├── softplus.m │ ├── symFcn.m │ └── types of activations available in matlab.txt ├── Conversion func │ ├── array2binStr.m │ ├── bin2num2.m │ ├── binStr2Array.m │ ├── binaryVector2doubleOutput.m │ ├── dec2discreteInputVector.m │ ├── double2binaryInputVector.m │ └── sepblockfun.m ├── Database Search Methods │ ├── PSO.m │ ├── PSO_evaluateTasks.m │ ├── PSO_swarm_sensitivity.m │ ├── multitaskPSO.m │ ├── psoOnDatabase.m │ ├── runPSOsearch.m │ ├── searchDatabase.m │ └── statsPSO.m ├── Datasets │ ├── CML.m │ ├── F1Score.m │ ├── JapaneseVowels │ │ ├── Test_Jap_vowels.mat │ │ ├── Train_Jap_vowels.mat │ │ ├── blockNo.mat │ │ ├── blockNumbers.txt │ │ ├── readJapVowels.m │ │ ├── test.asv │ │ ├── test.txt │ │ └── train.txt │ ├── KFoldXValidation.m │ ├── MNIST │ │ ├── loadMNISTImages.m │ │ ├── loadMNISTLabels.m │ │ ├── t10k-images.idx3-ubyte │ │ ├── t10k-labels.idx1-ubyte │ │ ├── train-images-idx3-ubyte.gz │ │ ├── train-images.idx3-ubyte │ │ └── train-labels.idx1-ubyte │ ├── Mackey_Glass_t17.txt │ ├── NS_training_data.mat │ ├── NonLinear_ChanEQ_data.m │ ├── attractorSwitch.m │ ├── banknotAuth.txt │ ├── compareIPIXfigure.m │ ├── coupledLogisticMaps.m │ ├── createDuffingOscillator.m │ ├── createIPIXfigure.m │ ├── createLimitCycleAttractor.m │ ├── createLorenz.m │ ├── createMackeyGlass.m │ ├── createMaze.m │ ├── createRosslerAttractor.m │ ├── displayMemNonlinMap.m │ ├── featureNormailse.m │ ├── featureNormalize.m │ ├── franke2d.m │ ├── generateHenonMap.m │ ├── generate_new_NARMA_sequence.m │ ├── getAdderTruthTable.m │ ├── getImage.m │ ├── handDigits.mat │ ├── input_decay_example.m │ ├── iris.mat │ ├── laser.txt │ ├── loIPIX.txt │ ├── makeMaze.m │ ├── matlab-maze │ │ ├── README.md │ │ └── maze.m │ ├── maze.m │ ├── poleBalance.m │ ├── robot.m │ ├── rsquared.m │ ├── selectDataset.asv │ ├── selectDataset.m │ ├── selectDataset_Rodan.m │ ├── split_train_test3way.m │ ├── sunspot.txt │ └── truth_table.m ├── Metrics │ ├── crossMC.m │ ├── entropyCombination.m │ ├── getMetrics.m │ ├── getMetrics_Seeded.m │ ├── infodynamics.jar │ ├── lyapunovExponent.m │ ├── mutualInformation.m │ ├── nonlinearMC.m │ ├── quadraticMC.m │ ├── testMC.m │ └── transferEntropy.m ├── NSGA-II │ ├── calc_crowding.m │ ├── calc_dommat.m │ ├── calc_prefdist.m │ ├── calc_stats.m │ ├── calc_wnorm_dist.m │ ├── constraints_function.m │ ├── crossoverNSGAII.m │ ├── evaluateNSGAII.m │ ├── extract_population.m │ ├── fitnessNSGAII.m │ ├── get_front.m │ ├── mutNSGAII.m │ ├── nd_sort.m │ ├── plot_front.m │ └── selectionNSGAII.m ├── Plots │ ├── Plot code dependencies │ │ ├── plot_depfun.m │ │ └── plot_graph.m │ ├── adjancencyMatrixPlot.m │ ├── behaviourGUI.fig │ ├── behaviourGUI.m │ ├── bluewhitered.m │ ├── calculateNumEdges.m │ ├── cubehelix.m │ ├── cubehelix_find.m │ ├── cubehelix_view.m │ ├── distinguishable_colors.m │ ├── filmDatabase.m │ ├── filmNS.m │ ├── getAdjacenyMatrix.m │ ├── logfit.m │ ├── parfor progress bar │ │ ├── ParforProgMon.m │ │ ├── Readme.md │ │ ├── java │ │ │ ├── ParforProgressMonitor$1.class │ │ │ ├── ParforProgressMonitor$ProgServer$1.class │ │ │ ├── ParforProgressMonitor$ProgServer.class │ │ │ ├── ParforProgressMonitor$ProgThing.class │ │ │ ├── ParforProgressMonitor$ProgWorker.class │ │ │ ├── ParforProgressMonitor.class │ │ │ └── ParforProgressMonitor.java │ │ ├── license.txt │ │ └── progress_bar.png │ ├── plotAEWeights.m │ ├── plotActivity.m │ ├── plotAndCalcSR.m │ ├── plotBS.m │ ├── plotBSVoxelfrequency.m │ ├── plotBZ.m │ ├── plotBZinputlayer.m │ ├── plotCA.m │ ├── plotCASearch.m │ ├── plotDatabaseComparison.m │ ├── plotDatabaseCoverage.m │ ├── plotDatabases.m │ ├── plotGraphWeights.m │ ├── plotGridNeuron.m │ ├── plotInputConnectivity.m │ ├── plotInternalConnectivity.m │ ├── plotParameter.asv │ ├── plotParameter.m │ ├── plotQuality.m │ ├── plotQualityRatio.m │ ├── plotRBN.m │ ├── plotRandvsNS.m │ ├── plotRandvsNS_ratioPlot.m │ ├── plotReservoirDetails.m │ ├── plotRoR.m │ ├── plotSearch.m │ ├── plotSearchwithTask.m │ ├── plotSpace.m │ ├── plot_depfun.m │ ├── schemaball.m │ ├── stdshade.m │ ├── violin.m │ └── weightStructure.m ├── Prediction │ ├── learnFNNModel.m │ ├── learnFNNModel2.m │ ├── learnFNNModel_ALL.m │ ├── learnMultiFNNModel.m │ ├── learnRegressionModel.m │ ├── predictTaskError.m │ ├── runBTreeScript.m │ ├── runFNNscript.m │ ├── runFNNscript_AllSizes.m │ ├── taskPrediction.m │ ├── trainFNNpredictor.m │ ├── trainMultiFNNpredictor.m │ └── trainRegressionModel.m ├── Pruning │ ├── maxPruning.m │ └── pruneDatabase.m ├── adjustInputShape.m ├── calculateError.m ├── cluster files │ ├── viking_charc.m │ └── viking_rand_SW.m ├── computeNRMSE.m ├── compute_NRMSE.m ├── convertCHARC2MAPelite.m ├── getError.m ├── getLeakStates.m ├── iirFilterStates.m ├── measureSearchSpace.m ├── recursiveDivision.m ├── rk4_2.m ├── saveData.m ├── selectReservoirType.m ├── stepResponse.m ├── testReservoir.asv └── testReservoir.m └── reservoir-type ├── BZ reservoir ├── assessBZReservoir.m ├── createBZReservoir.m ├── mutateBZ.m └── recombBZ.m ├── Boolean Network Reservoir ├── assessRBNreservoir.m ├── assocNeighbours.m ├── assocRules.m ├── createRBNreservoir.m ├── evolveARBN.m ├── evolveCRBN.m ├── evolveDARBN.m ├── evolveDGARBN.m ├── getECAclass.m ├── getStateVector.m ├── initConnections.m ├── initNodes.m ├── initRules.m ├── mutateRBN.m ├── recombRBN.m ├── resetNodeStats.m ├── setLUTLines.m └── setNodeNextState.m ├── CA ├── GameOfLife.m ├── assessGOL.m ├── createGOL.m ├── mutateGOL.m ├── recombGOL.m └── testGOL_digits.m ├── DNA reservoir ├── assessDNAreservoir.m ├── createDNAreservoir.m ├── mutateDNA.m ├── recombDNA.m └── rk4_2.m ├── Delay-Line Reservoirs ├── collectDLStates.m ├── createDLReservoir.m ├── mutateDL.m └── recombDL.m ├── ELM ├── collectELMStates.m └── createELM.m ├── Graph Reservoir ├── assessGraphReservoir.m ├── createGraphReservoir.m ├── createLattice.m ├── cubelet.m ├── cylinder.m ├── generatelattices.m ├── getShape.m ├── hypercube.m ├── plotGraphNeuron.m └── torusGraph.m ├── Hardware └── CNT │ ├── collectCNTStates.m │ ├── createCNT.m │ ├── mutateCNT.m │ ├── recombCNT.m │ └── setUpSwitch.m ├── Multi-reservoir ├── Ensemble Res │ ├── collectEnsembleStates.m │ └── createEnsemble.m ├── Pipeline - DeepESN │ ├── collectPipelineStates.m │ └── createPipeline.m └── RoR architecture │ ├── assessESNonTask.m │ ├── collectRoRStates.m │ ├── createRoR.m │ ├── generate_internal_weights.m │ ├── mutateRoR.m │ └── recombRoR.m ├── Small-world ├── createSWReservoir.m ├── mutateSW.m └── recombSW.m ├── Wave ├── Wave_sim.m ├── collectWaveStates.m ├── createWave.m ├── mutateWave.m └── recombWave.m ├── _Template Reservoir ├── _assess_ReservoirName_.m ├── _create_ReservoirName_.m ├── _mutate_ReservoirName_.m └── _recomb_ReservoirName_.m ├── getAdditionalParameters.m └── selectReservoirType.m /Support files/Simulators/robot-sim/mars_install/Addons/Map/Map_Initialize.m: -------------------------------------------------------------------------------- 1 | function [Exp_status]=Map_Initialize(Exp_status) 2 | % Compute Obstacle Grid 3 | 4 | %-- Check if the Map field exist 5 | if (~isfield(Exp_status,'Map')) 6 | Exp_status.Map.Obstacle_grid.Enable=false; 7 | Exp_status.Map.Obstacle_distance.Enable=false; 8 | Exp_status.Map.Obstacle=[]; 9 | end 10 | %------ 11 | 12 | %-- if Obstacle_grid is disabled exit 13 | if (isfield(Exp_status.Map,'Obstacle_grid')) && (isfield(Exp_status.Map.Obstacle_grid,'Enable')) && (Exp_status.Map.Obstacle_grid.Enable==false), 14 | return, 15 | else 16 | Exp_status.Map.Obstacle_grid.Enable=true; 17 | end 18 | %------ 19 | 20 | %-- set Obstacle_grid resolution 21 | if (~isfield(Exp_status.Map.Obstacle_grid,'Resolution')) 22 | Exp_status.Map.Obstacle_grid.Resolution=0.01; % cell size 1 centimeter (default) 23 | end 24 | resolution=Exp_status.Map.Obstacle_grid.Resolution; 25 | %------ 26 | 27 | %-- compute matrix size and offset 28 | lenx=(Exp_status.Bounds(2)-Exp_status.Bounds(1))/resolution; 29 | leny=(Exp_status.Bounds(4)-Exp_status.Bounds(3))/resolution; 30 | M_offset=Exp_status.Bounds([1,3])'; 31 | M_grid=zeros(leny,lenx); 32 | %------ 33 | 34 | %-- fill in matrix elements cycling for each obstacle 35 | V=Exp_status.Map.Obstacle; 36 | for k=1:length(V) 37 | V(k).Vertex(:,1)=(V(k).Vertex(:,1)-M_offset(1))/resolution; 38 | V(k).Vertex(:,2)=(V(k).Vertex(:,2)-M_offset(2))/resolution; 39 | x=V(k).Vertex(:,1); 40 | y=V(k).Vertex(:,2); 41 | M_grid_temp=poly2mask(x,leny-y,leny,lenx); 42 | M_grid=max(M_grid,k*M_grid_temp); 43 | end 44 | %------ 45 | 46 | Exp_status.Map.Obstacle_grid.Grid=M_grid; 47 | Exp_status.Map.Obstacle_grid.Offset=M_offset; 48 | 49 | [Exp_status]=Map_Loop(Exp_status); % Run Map_loop to compute initial distances 50 | end 51 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Map/Map_Loop.m: -------------------------------------------------------------------------------- 1 | function [Exp_status]=Map_Loop(Exp_status) 2 | % Compute Obstacle_distance and Robot_distance 3 | 4 | Pose=Exp_status.Pose; 5 | n_robot=Exp_status.Robots; 6 | n_object=length(Exp_status.Map.Obstacle); 7 | 8 | %-- Compute Obstacle_distance 9 | if (~isfield(Exp_status.Map,'Obstacle_distance')) || (~isfield(Exp_status.Map.Obstacle_distance,'Enable')) || (Exp_status.Map.Obstacle_distance.Enable==true) 10 | D_obstacle=[]; 11 | for w=1:n_robot 12 | for k=1:n_object 13 | [distance,px,py]=p_poly_dist(Pose(1,w),Pose(2,w),Exp_status.Map.Obstacle(k).Vertex(:,1),Exp_status.Map.Obstacle(k).Vertex(:,2)); 14 | D_obstacle(w,k).Min_dist=distance; 15 | D_obstacle(w,k).P_min=[px ; py]; 16 | end 17 | end 18 | Exp_status.Map.Obstacle_distance=D_obstacle; 19 | end 20 | %------ 21 | 22 | %-- Compute Robot_distance 23 | if (~isfield(Exp_status.Map,'Robot_distance')) || (~isfield(Exp_status.Map.Robot_distance,'Enable')) || (Exp_status.Map.Robot_distance.Enable==true) 24 | D_robot=zeros(n_robot,n_robot); 25 | for w=1:n_robot-1 26 | for e=w+1:n_robot 27 | D_robot(w,e)=norm(Pose(1:2,w)-Pose(1:2,e)); 28 | D_robot(e,w)=D_robot(w,e); 29 | end 30 | end 31 | Exp_status.Map.Robot_distance=D_robot; 32 | end 33 | %------ 34 | 35 | end 36 | 37 | 38 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Map/Map_Plot.m: -------------------------------------------------------------------------------- 1 | function [Exp_status]=Map_Plot(Exp_status) 2 | 3 | %-- Plot obstacles 4 | if (isfield(Exp_status,'Map')), 5 | V=Exp_status.Map.Obstacle; 6 | for h=1:length(V) 7 | set(Exp_status.Map.Obstacle(h).Handle_patch,'XData',V(h).Vertex(:,1),'YData',V(h).Vertex(:,2)); 8 | end 9 | end 10 | %------ 11 | 12 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Map/Map_Plot_Initialize.m: -------------------------------------------------------------------------------- 1 | function [Exp_status]=Map_Plot_Initialize(Exp_status) 2 | 3 | %-- Plot obstacles 4 | if (isfield(Exp_status,'Map')), 5 | V=Exp_status.Map.Obstacle; 6 | for h=1:length(V) 7 | Exp_status.Map.Obstacle(h).Handle_patch=patch(V(h).Vertex(:,1),V(h).Vertex(:,2),[.8 .8 .8]); 8 | end 9 | end 10 | %------ 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Peg/Peg_Initialize.m: -------------------------------------------------------------------------------- 1 | function [Exp_Status]=Peg_Initialize(Exp_Status) 2 | 3 | PEG_default_speed=0.1; % Default max linear speed (m/s) 4 | if ~isfield(Exp_Status.Peg,'Speed'), 5 | Exp_Status.Peg.Speed(1: Exp_Status.Robots)=PEG_default_speed; 6 | end 7 | end 8 | 9 | 10 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Peg/Peg_Loop.m: -------------------------------------------------------------------------------- 1 | function [Exp_Status]=Peg_Loop(Exp_Status) 2 | % Check bounds, collisions, timeout and winner 3 | 4 | %-- Check bounds 5 | [outside,idx]=Check_bounds(Exp_Status); 6 | if outside 7 | msg=['\nRobot #',num2str(idx),' outside bounds.\n']; 8 | if Exp_Status.Peg.Role(idx)=='P', msg=[msg, 'EVADER WINS!\n\n']; else msg=[msg, 'PURSUER WINS!\n\n']; end 9 | Exp_Status.Exp_over=true; 10 | Exp_Status.Exp_over_msg=msg; 11 | return 12 | end 13 | %------ 14 | 15 | %-- Check collisions 16 | [collision, M_idx]=Check_collision(Exp_Status); 17 | if collision 18 | E_collision=false; 19 | msg='\nCollision detected.\n'; 20 | for i=1:Exp_Status.Robots 21 | if Exp_Status.Peg.Role(i)=='E' 22 | if any(M_idx(i,:)), E_collision = true; end 23 | end 24 | end 25 | if E_collision, msg=[msg, 'PURSUER WINS!\n\n']; 26 | else msg=[msg, 'EVADER WINS!\n\n']; end 27 | Exp_Status.Exp_over=true; 28 | Exp_Status.Exp_over_msg=msg; 29 | return 30 | end 31 | %------ 32 | 33 | %-- Check timeout 34 | if Exp_Status.Time>=Exp_Status.Stop_time 35 | msg='\nTime is over.\nEVADER WINS!\n\n'; 36 | Exp_Status.Exp_over=true; 37 | Exp_Status.Exp_over_msg=msg; 38 | end 39 | %------ 40 | end 41 | 42 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Peg/Peg_Plot_Initialize.m: -------------------------------------------------------------------------------- 1 | function [Exp_Status]=Peg_Plot_Initialize(Exp_Status) 2 | 3 | Pursuers=(Exp_Status.Peg.Role=='P'); 4 | Evaders=(Exp_Status.Peg.Role=='E'); 5 | 6 | Exp_Status.Animation.Colors(Pursuers)='k'; % pursuers = black 7 | Exp_Status.Animation.Colors(Evaders)='b'; % Evader = red 8 | end 9 | 10 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Voronoi/Voronoi_Plot.m: -------------------------------------------------------------------------------- 1 | function [EXP]=Voronoi_Plot(EXP) 2 | 3 | %-- Plot Voronoi cells and centroids 4 | if isfield(EXP,'Voronoi')&& isfield(EXP.Voronoi,'Cell') 5 | for h=1:EXP.Robots 6 | if isfield(EXP.Voronoi.Cell(h),'Visible_cell') 7 | if (EXP.Voronoi.Cell(h).Visible_cell), 8 | set(EXP.Voronoi.Cell(h).Handle_patch,'XData',EXP.Voronoi.Cell(h).Vertex(:,1),'YData',EXP.Voronoi.Cell(h).Vertex(:,2)); 9 | end 10 | end 11 | 12 | if isfield(EXP.Voronoi.Cell(h),'Visible_centroid') 13 | if (EXP.Voronoi.Cell(h).Visible_centroid)&& isfield(EXP.Voronoi.Cell(h),'Enable_centroid_computation')&& (EXP.Voronoi.Cell(h).Enable_centroid_computation), 14 | set(EXP.Voronoi.Cell(h).Handle_centroid,'XData',EXP.Voronoi.Cell(h).Centroid(1),'YData',EXP.Voronoi.Cell(h).Centroid(2)); 15 | end 16 | end 17 | end 18 | end 19 | 20 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Voronoi/Voronoi_Plot_Initialize.m: -------------------------------------------------------------------------------- 1 | function [EXP]=Voronoi_Plot_Initialize(EXP) 2 | 3 | for h=1:EXP.Robots; 4 | EXP.Voronoi.Cell(h).Handle_patch=patch(0,0,EXP.Animation.Colors(1+mod(h,EXP.Robots))); %-- Define handles for plotting centroids 5 | EXP.Voronoi.Cell(h).Handle_centroid=plot(inf,inf,['o',EXP.Animation.Colors(h)]); %-- Define handles for plotting Voronoi cells 6 | % set(EXP.Voronoi.Cell(h).Handle_patch,'LineWidth',1,'FaceColor',[1 0.9 0.9]); 7 | end 8 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Addons/Voronoi/todo.txt: -------------------------------------------------------------------------------- 1 | To be fix: plot of voronoi cells for nonconvex workspace. 2 | 3 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Circle.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=Demo_Circle(Exp_status,Initialization) 2 | % Robots move uniformely distributed around a given circle path. 3 | % No collision avoidance is implemented 4 | 5 | %-- Experiment initialization 6 | if Initialization 7 | Command=[]; 8 | Exp_status.Workspace=[0 0; 0 4 ; 4 4; 4 0; 0 0]; % Workspace definition 9 | Exp_status.Robots=4; % Number of robot used 10 | 11 | %-- Animation setting 12 | % Exp_status.Animation.Wake=0; % disable robot wake 13 | % Exp_status.Animation.Show_initial_pose=0; % hide initial position 14 | % Exp_status.Animation.Grid=0; % remove grid 15 | %-- 16 | return 17 | end 18 | %------ 19 | 20 | % %-- Define circular trajectory to be followed by robots 21 | C=[2; 2]; % center 22 | R=1; % radius 23 | Period=100; % period 24 | % %------ 25 | % 26 | %-- Robot speed computation 27 | for k=1:Exp_status.Robots 28 | desired_pose(1:2,k)=C+R*[cos((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots)) ; sin((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots))]; 29 | desired_pose(3,k)=atan2(-(desired_pose(2,k)-C(2)),-(desired_pose(1,k)-C(1))); 30 | Command(:,k)=move_to(Exp_status,Exp_status.Pose(:,k),desired_pose(:,k),0.5); 31 | end 32 | %------ 33 | end 34 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Holonomic.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_Status]=Demo_Holonomic(Exp_Status,Initialization) 2 | % Demo of pursuit-evasion game (PEG) 3 | % Robots have holonomic drive 4 | % The "Peg" addon is used in this demo 5 | 6 | %-- Experiment definition 7 | if Initialization 8 | Command=[]; 9 | Exp_Status.Workspace=[0 0; 0 3 ; 5 3; 5 0; 0 0]; 10 | Exp_Status.Initial_pose=[1 1.5; 3 1.5]'; 11 | Exp_Status.Robots=2; % Number of robot used 12 | Exp_Status.Addons={'Peg'}; % Enable pursuer-evader addon 13 | Exp_Status.Peg.Role='PE'; % Robots roles 14 | Exp_Status.Peg.Speed=[0.1 ; 0.15]; % Robots speed 15 | Exp_Status.Non_holonomic=false; % holonomic drive 16 | return 17 | end 18 | %------ 19 | 20 | CommandP=PEG_Pursuer(Exp_Status,Exp_Status.Peg.Speed(1)); 21 | CommandE=PEG_Evader(Exp_Status,Exp_Status.Peg.Speed(2)); 22 | Command=[CommandP , CommandE, CommandP, CommandE, CommandP]; 23 | end 24 | 25 | % ************ Pursuer Algorithm ************ 26 | function Command=PEG_Pursuer(Exp_status,v_max) 27 | dir=(Exp_status.Pose(1:2,2)-Exp_status.Pose(1:2,1)); 28 | Command=v_max*dir/norm(dir); 29 | end 30 | %------ 31 | 32 | % ************ Evader 4 vertexes ************ 33 | function Command=PEG_Evader(EXP,v_max) 34 | persistent des_pose status 35 | DIST_THRESHOLD=0.7; 36 | STATUS_THRESHOLD=0.2; 37 | Q(:,1)=[4.5 2.5 5*pi/4]'; 38 | Q(:,2)=[0.5 2.5 -pi/4]'; 39 | Q(:,3)=[0.5 0.5 pi/4]'; 40 | Q(:,4)=[4.5 0.5 3*pi/4]'; 41 | Pose=EXP.Pose; 42 | if isempty(des_pose), status=4; des_pose=1; end 43 | if norm(Q(1:2,des_pose)-Pose(1:2,2))3*pi/4), des_pose=3; else des_pose=1; end 51 | case 3, if (abs(ang)>3*pi/4), des_pose=2; else des_pose=4; end 52 | case 4, if (abs(ang)v_max, 58 | dir=(dir/norm(dir))*v_max; 59 | end 60 | Command=dir; 61 | end 62 | 63 | 64 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Open_Space.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=Demo_Open_Space(Exp_status,Initialization) 2 | % Example of open space environment 3 | % Robots move uniformely distributed around a given circle path. 4 | % No collision avoidance is implemented 5 | % If Exp_status.Workspace is not defined, an open environment is assumed 6 | 7 | %-- Experiment initialization 8 | if Initialization 9 | Command=[]; 10 | Exp_status.Initial_pose=[3.5 2.5 0; 4 2 0 ; 1 1.5 0 ; 0.5 2 0]'; 11 | Exp_status.Robots=4; % Number of robot used 12 | 13 | %-- Animation setting 14 | % Exp_status.Animation.Wake=0; % disable robot wake 15 | % Exp_status.Animation.Show_initial_pose=0; % hide initial position 16 | % Exp_status.Animation.Grid=0; % remove grid 17 | %-- 18 | return 19 | end 20 | %------ 21 | 22 | % %-- Define circular trajectory to be followed by robots 23 | C=[2; 2]; % center 24 | R=5; % radius 25 | Period=300; % period 26 | % R=1+Exp_status.Time/30; % radius 27 | % Period=100+Exp_status.Time/10; % period 28 | % %------ 29 | % 30 | %-- Robot speed computation 31 | for k=1:Exp_status.Robots 32 | desired_pose(1:2,k)=C+R*[cos((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots)) ; sin((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots))]; 33 | desired_pose(3,k)=atan2(-(desired_pose(2,k)-C(2)),-(desired_pose(1,k)-C(1))); 34 | Command(:,k)=move_to(Exp_status,Exp_status.Pose(:,k),desired_pose(:,k),0.5); 35 | end 36 | %------ 37 | end 38 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Square.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=Demo_Square(Exp_status,Initialization) 2 | % Four robots moving to the vertex of a square. 3 | % No collision avoidance is implemented 4 | 5 | %-- Experiment definition 6 | if Initialization 7 | Command=[]; 8 | Exp_status.Workspace=[0 0; 0 4 ; 4 4; 4 0; 0 0]; 9 | % Exp_Status.Initial_pose=[3.5 2.5 0; 4 2 0 ; 1 1.5 0 ; 0.5 2 0]'; 10 | Exp_status.Robots=4; % Number of robot used 11 | return 12 | end 13 | %------ 14 | 15 | x0=1.0; y0=1; % bottom-left vertex 16 | R=2; % side length 17 | s=floor(Exp_status.Time/30); % time interval 18 | Q(:,1)=[x0 y0 90*pi/180]'; 19 | Q(:,2)=[x0 y0+R 0*pi/180]'; 20 | Q(:,3)=[x0+R y0+R -90*pi/180]'; 21 | Q(:,4)=[x0+R y0 180*pi/180]'; 22 | desired_pose(:,4)=Q(:,mod(s,4)+1); 23 | desired_pose(:,2)=Q(:,mod(s+1,4)+1); 24 | desired_pose(:,1)=Q(:,mod(s+2,4)+1); 25 | desired_pose(:,3)=Q(:,mod(s+3,4)+1); 26 | for i=1:Exp_status.Robots 27 | Command(:,i)=move_to(Exp_status,Exp_status.Pose(:,i),desired_pose(:,i),0.5); 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Unbounded.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=Demo_Unbounded(Exp_status,Initialization) 2 | % Example of unbouded environment 3 | % Robots move uniformely distributed around a given circle path. 4 | % No collision avoidance is implemented 5 | % If Exp_status.Workspace is closed, bounded environment is assumed 6 | 7 | %-- Experiment initialization 8 | if Initialization 9 | Command=[]; 10 | Exp_status.Workspace=[4 0 ;0 0; 0 4 ; 4 4]; % Workspace definition 11 | Exp_status.Initial_pose=[3.5 2.5 0; 4 2 0 ; 1 1.5 0 ; 0.5 2 0]'; 12 | Exp_status.Robots=4; % Number of robot used 13 | 14 | %-- Animation setting 15 | % Exp_status.Animation.Wake=0; % disable robot wake 16 | % Exp_status.Animation.Show_initial_pose=0; % hide initial position 17 | % Exp_status.Animation.Grid=0; % remove grid 18 | %-- 19 | return 20 | end 21 | %------ 22 | 23 | % %-- Define circular trajectory to be followed by robots 24 | C=[3.5; 2]; % center 25 | R=1.5; % radius 26 | Period=100; % period 27 | % R=1+Exp_status.Time/30; % radius 28 | % Period=100+Exp_status.Time/10; % period 29 | % %------ 30 | % 31 | %-- Robot speed computation 32 | for k=1:Exp_status.Robots 33 | desired_pose(1:2,k)=C+R*[cos((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots)) ; sin((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots))]; 34 | desired_pose(3,k)=atan2(-(desired_pose(2,k)-C(2)),-(desired_pose(1,k)-C(1))); 35 | Command(:,k)=move_to(Exp_status,Exp_status.Pose(:,k),desired_pose(:,k),0.5); 36 | end 37 | %------ 38 | end 39 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Demos/Demo_Voronoi.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=Demo_Voronoi(Exp_status,Initialization) 2 | % Demo of coverage task. 3 | % The "Voronoi" addon is used in this demo to compute and plot Voronoi cell 4 | 5 | %-- Experiment definition 6 | if Initialization 7 | Command=[]; 8 | Exp_status.Workspace=[0 0; 0 4 ; 4 4; 4 0; 0 0]; 9 | % Exp_status.Workspace=[0 0; 0 4 ; 2 6; 6 5;3 4; 4 0]; 10 | % Exp_status.Initial_pose=[1 1 0; 2 1 0; 3 2 0]'; 11 | Exp_status.Robots=3; % Number of robot used 12 | Exp_status.Addons={'Voronoi'}; % Enable voronoi addon 13 | for k=1:Exp_status.Robots 14 | Exp_status.Voronoi.Cell(k).Visible_cell=1; 15 | Exp_status.Voronoi.Cell(k).Enable_centroid_computation=1; 16 | Exp_status.Voronoi.Cell(k).Visible_centroid=1; 17 | end 18 | return 19 | end 20 | %------ 21 | 22 | %-- circolar trajectories definition 23 | C=[2; 2]; % center 24 | R=1; % radius 25 | Period=100; % period 26 | 27 | for k=1:Exp_status.Robots 28 | desired_pose(1:2,k)=C+R*[cos((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots)) ; sin((2*pi*Exp_status.Time/Period+(k-1)*2*pi/Exp_status.Robots))]; 29 | desired_pose(3,k)=atan2(-(desired_pose(2,k)-C(2)),-(desired_pose(1,k)-C(1))); 30 | Command(:,k)=move_to(Exp_status,Exp_status.Pose(:,k),desired_pose(:,k),.5); 31 | end 32 | %------ 33 | end 34 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Check_Obs_collision.m: -------------------------------------------------------------------------------- 1 | function [collision, M_idx]=Check_Obs_collision(EXP) 2 | % check if collision between robots and objects 3 | 4 | collision=false; 5 | 6 | if isfield(EXP,'Map')&& isfield(EXP.Map,'Obstacle_distance') 7 | for s=1:length(EXP.Map.Obstacle) % ciclo sugli ostacoli 8 | if abs(EXP.Map.Obstacle_distance(s).Min_dist) < 0.1 9 | collision=true; 10 | end 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Check_bounds.m: -------------------------------------------------------------------------------- 1 | function [outside,idx]=Check_bounds(EXP) 2 | % Check if robots are outside the safety bounds 3 | % outside = 0, ok. outside = 1, at least 1 robot is outside the bounds 4 | % idx contains the indexes of robots outside bounds 5 | 6 | switch EXP.Workspace_type 7 | case 0 % open space 8 | outside=false; idx=0; 9 | case 1 % unbounded region 10 | outside=false; idx=0; 11 | % TO BE DONE... 12 | 13 | case 2 % bounded polygon 14 | inside=inpolygon(EXP.Pose(1,:),EXP.Pose(2,:),EXP.Workspace(:,1),EXP.Workspace(:,2)); 15 | idx=find(inside==0); 16 | outside=sum(idx)>0; 17 | end 18 | end -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Check_collision.m: -------------------------------------------------------------------------------- 1 | function [collision, M_idx]=Check_collision(EXP) 2 | % check if collision between robots is occurred (or is going to occur) 3 | 4 | if EXP.Robots==1 5 | collision=false; 6 | M_idx=0; 7 | return; 8 | end 9 | 10 | collision=false; 11 | M_idx=zeros(EXP.Robots); 12 | 13 | cx=EXP.Geometric_center(1,:); 14 | cy=EXP.Geometric_center(2,:); 15 | 16 | for i=1:EXP.Robots-1 17 | for j=i+1:EXP.Robots 18 | dist=norm([cx(i) ; cy(i)]-[cx(j) ; cy(j)]); 19 | if dist<=EXP.Robot.Diameter 20 | collision=true; 21 | M_idx(i,j)=1; 22 | end 23 | end 24 | end 25 | end -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/Add_sensor.m: -------------------------------------------------------------------------------- 1 | function [Exp_status]=Add_sensor(Exp_status,n_robot,sensors) 2 | % Add sensors to a given robot. 3 | % n_robot denote the robot number 4 | % sensors contains codes of sensors 5 | 6 | %-- load sensor characteristics if needed 7 | if (~isfield(Exp_status,'Sensor')) 8 | Exp_status=Load_sensors(Exp_status); 9 | Exp_status.Agent(Exp_status.Robots).Sensor=[]; % initialize sensor structure for all robots 10 | end 11 | %------ 12 | 13 | num_sensors=length(sensors); 14 | 15 | for i=1:num_sensors 16 | code=char(sensors(i)); % sensor code 17 | sensor_found=false; 18 | id=1; 19 | while (~sensor_found)&&(id<=length(Exp_status.Sensor)) 20 | if strcmp(Exp_status.Sensor(id).Code,code) 21 | S=Exp_status.Sensor(id); 22 | if (i==1), Exp_status.Agent(n_robot).Sensor=S; else Exp_status.Agent(n_robot).Sensor(i)=S; end 23 | sensor_found=true; 24 | end 25 | id=id+1; 26 | end 27 | if ~sensor_found 28 | error('Sensor "%s" not found!\nSimulation aborted!\n',code); 29 | end 30 | end 31 | end -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/Load_sensors.m: -------------------------------------------------------------------------------- 1 | function Exp_status=Load_sensors(Exp_status) 2 | % Load the characteristics of sensors 3 | 4 | %-- Proximity sensor 5 | % return true if an obstacle or a robot is within a circle around the robot 6 | Sensor(1).Code='ProximitySensor'; 7 | Sensor(1).Description='Sensor able to detect obstacles and/or robots within a circular area around the robot.'; 8 | Sensor(1).Range=1; 9 | Sensor(1).Show_range=true; 10 | %------ 11 | 12 | %-- Range finder sensor (real) 13 | Sensor(2).Code='RangeFinder'; 14 | Sensor(2).Description='Sensor implementing a laser range finder.'; 15 | Sensor(2).Range=1; % distance range 16 | Sensor(2).Angle_span=pi; % angle of vision 17 | Sensor(2).Number_of_measures=181; 18 | Sensor(2).Show_range=true; 19 | Sensor(2).Show_beam=false; 20 | %------ 21 | 22 | %-- Ideal range finder sensor 23 | Sensor(3).Code='RangeFinderIdeal'; 24 | Sensor(3).Description='Sensor implementing an ideal laser range finder, able to return the exact pose of robots inside the visibility cone.'; 25 | Sensor(3).Range=1; % distance range 26 | Sensor(3).Angle_span=pi; % angle of vision 27 | Sensor(3).Show_range=true; 28 | %------ 29 | 30 | 31 | Exp_status.Sensor=Sensor; 32 | 33 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/Manage_sensors.m: -------------------------------------------------------------------------------- 1 | function Exp_status=Manage_sensors(Exp_status) 2 | % Run computation of sensor outputs (for each sensor) and draw plot 3 | 4 | if (~isfield(Exp_status,'Agent')), return; end 5 | 6 | for n_robot=1:Exp_status.Robots 7 | for n_sensor=1:length(Exp_status.Agent(n_robot).Sensor) 8 | eval(['Exp_status=' Exp_status.Agent(n_robot).Sensor(n_sensor).Code '_compute(Exp_status,' num2str(n_robot) ',' num2str(n_sensor)' ');']); 9 | %--Run plot function if the feature is visible and animation is enabled 10 | if (Exp_status.Animation.Enable)&&((~isfield(Exp_status.Agent(n_robot).Sensor(n_sensor),'Visible'))||(isempty(Exp_status.Agent(n_robot).Sensor(n_sensor).Visible)||(Exp_status.Agent(n_robot).Sensor(n_sensor).Visible))) 11 | eval(['Exp_status=' Exp_status.Agent(n_robot).Sensor(n_sensor).Code '_plot(Exp_status,' num2str(n_robot) ',' num2str(n_sensor)' ');']); 12 | end 13 | %------ 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/ProximitySensor_compute.m: -------------------------------------------------------------------------------- 1 | function [EXP]=ProximitySensor_compute(EXP,n_robot,n_sensor) 2 | 3 | EXP.Agent(n_robot).Sensor(n_sensor).Presence=false; 4 | EXP.Agent(n_robot).Sensor(n_sensor).Detected_robots=[]; 5 | EXP.Agent(n_robot).Sensor(n_sensor).Detected_obstacles=[]; 6 | 7 | %-- Compute sensor output 8 | %-- Check robots 9 | for i=1:EXP.Robots 10 | if (i~=n_robot) 11 | if (norm(EXP.Pose(1:2,n_robot)-EXP.Pose(1:2,i))<=EXP.Agent(n_robot).Sensor(n_sensor).Range) 12 | EXP.Agent(n_robot).Sensor(n_sensor).Presence=true; 13 | EXP.Agent(n_robot).Sensor(n_sensor).Detected_robots=[EXP.Agent(n_robot).Sensor(n_sensor).Detected_robots , i]; 14 | end 15 | end 16 | end 17 | EXP.Agent(n_robot).Sensor(n_sensor).Detected_robots=unique(EXP.Agent(n_robot).Sensor(n_sensor).Detected_robots); 18 | %------ 19 | 20 | %-- Check obstacles 21 | if isfield(EXP,'Map') 22 | for i=1:length(EXP.Map.Obstacle) 23 | if (EXP.Map.Obstacle_distance(n_robot,i).Min_dist<=EXP.Agent(n_robot).Sensor(n_sensor).Range) 24 | EXP.Agent(n_robot).Sensor(n_sensor).Presence=true; 25 | EXP.Agent(n_robot).Sensor(n_sensor).Detected_obstacles=[EXP.Agent(n_robot).Sensor(n_sensor).Detected_obstacles , i]; 26 | end 27 | end 28 | end 29 | %------ 30 | 31 | 32 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/ProximitySensor_plot.m: -------------------------------------------------------------------------------- 1 | function [EXP]=ProximitySensor_plot(EXP,n_robot,n_sensor) 2 | 3 | if (~isfield(EXP.Agent(n_robot).Sensor(n_sensor),'Plot_handler'))||(isempty(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler)) 4 | Plot_handler=plot(0,0,'LineStyle',':','Color',EXP.Animation.Colors(n_robot)); 5 | EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler=Plot_handler; 6 | end 7 | 8 | Sensor=EXP.Agent(n_robot).Sensor(n_sensor); 9 | Plot_handler=Sensor.Plot_handler; 10 | pose=EXP.Pose(:,n_robot); 11 | Range=Sensor.Range; 12 | 13 | if EXP.Agent(n_robot).Sensor(n_sensor).Show_range 14 | t = 0:0.1:2*pi+0.1; x = cos(t); y = sin(t); 15 | set(Plot_handler,'XData',pose(1)+Range*x,'YData',pose(2)+Range*y,'Visible','on'); 16 | else 17 | set(Plot_handler,'Visible','off'); 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinderIdeal_plot.m: -------------------------------------------------------------------------------- 1 | function [EXP]=RangeFinderIdeal_plot(EXP,n_robot,n_sensor) 2 | 3 | arc_resolution=20; % resolution for drawing the arc of circonference 4 | 5 | %-- Initialize handler for range plot 6 | if (~isfield(EXP.Agent(n_robot).Sensor(n_sensor),'Plot_handler'))||(isempty(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler)) 7 | Plot_handler=plot(0,0,'LineStyle','--','Color',EXP.Animation.Colors(n_robot)); 8 | EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler=Plot_handler; 9 | for j=1:EXP.Agent(n_robot).Sensor(n_sensor).Number_of_measures 10 | EXP.Agent(n_robot).Sensor(n_sensor).Beam_handler(j)=plot(0,0,'LineStyle',':','Color',EXP.Animation.Colors(n_robot)); 11 | end 12 | end 13 | %------ 14 | 15 | %-- Check and plot sensor range 16 | if EXP.Agent(n_robot).Sensor(n_sensor).Show_range 17 | angle_final=EXP.Pose(3,n_robot)-EXP.Agent(n_robot).Sensor(n_sensor).Angle_span/2; 18 | angle_iniz=EXP.Pose(3,n_robot)+EXP.Agent(n_robot).Sensor(n_sensor).Angle_span/2; 19 | t=linspace(angle_iniz,angle_final,ceil((angle_iniz-angle_final)*arc_resolution)); 20 | x = cos(t); y = sin(t); 21 | xd=[EXP.Pose(1,n_robot) EXP.Pose(1,n_robot)+EXP.Agent(n_robot).Sensor(n_sensor).Range*x EXP.Pose(1,n_robot)]; 22 | yd=[EXP.Pose(2,n_robot) EXP.Pose(2,n_robot)+EXP.Agent(n_robot).Sensor(n_sensor).Range*y EXP.Pose(2,n_robot)]; 23 | set(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler,'XData',xd,'YData',yd,'Visible','on'); 24 | else 25 | set(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler,'Visible','off'); 26 | end 27 | %------ 28 | end 29 | 30 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinder_compute.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinder_compute.asv -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinder_compute.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinder_compute.m -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/Sensors/RangeFinder_plot.m: -------------------------------------------------------------------------------- 1 | function [EXP]=RangeFinder_plot(EXP,n_robot,n_sensor) 2 | 3 | %-- Initialize handler for range plot 4 | if (~isfield(EXP.Agent(n_robot).Sensor(n_sensor),'Plot_handler'))||(isempty(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler)) 5 | Plot_handler=plot(0,0,'LineStyle','--','Color',EXP.Animation.Colors(n_robot)); 6 | EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler=Plot_handler; 7 | for j=1:EXP.Agent(n_robot).Sensor(n_sensor).Number_of_measures 8 | EXP.Agent(n_robot).Sensor(n_sensor).Beam_handler(j)=plot(0,0,'LineStyle',':','Color',EXP.Animation.Colors(n_robot)); 9 | end 10 | end 11 | 12 | %-- Check and plot sensor range 13 | if EXP.Agent(n_robot).Sensor(n_sensor).Show_range 14 | angle_final=EXP.Pose(3,n_robot)-EXP.Agent(n_robot).Sensor(n_sensor).Measured_angle(end); 15 | angle_iniz=EXP.Pose(3,n_robot)-EXP.Agent(n_robot).Sensor(n_sensor).Measured_angle(1); 16 | t=linspace(angle_iniz,angle_final,ceil((angle_iniz-angle_final)*20)); 17 | x = cos(t); y = sin(t); 18 | xd=[EXP.Pose(1,n_robot) EXP.Pose(1,n_robot)+EXP.Agent(n_robot).Sensor(n_sensor).Range*x EXP.Pose(1,n_robot)]; 19 | yd=[EXP.Pose(2,n_robot) EXP.Pose(2,n_robot)+EXP.Agent(n_robot).Sensor(n_sensor).Range*y EXP.Pose(2,n_robot)]; 20 | set(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler,'XData',xd,'YData',yd,'Visible','on'); 21 | else 22 | set(EXP.Agent(n_robot).Sensor(n_sensor).Plot_handler,'Visible','off'); 23 | end 24 | 25 | %-- Check and plot sensor beam 26 | if (EXP.Agent(n_robot).Sensor(n_sensor).Show_beam) 27 | x0=EXP.Pose(1,n_robot); y0=EXP.Pose(2,n_robot); 28 | for j=1:EXP.Agent(n_robot).Sensor(n_sensor).Number_of_measures 29 | if EXP.Agent(n_robot).Sensor(n_sensor).Measured_distance(j)~=-1 30 | x1=x0+cos(EXP.Pose(3,n_robot)-EXP.Agent(n_robot).Sensor(n_sensor).Measured_angle(j))*EXP.Agent(n_robot).Sensor(n_sensor).Measured_distance(j); 31 | y1=y0+sin(EXP.Pose(3,n_robot)-EXP.Agent(n_robot).Sensor(n_sensor).Measured_angle(j))*EXP.Agent(n_robot).Sensor(n_sensor).Measured_distance(j); 32 | set(EXP.Agent(n_robot).Sensor(n_sensor).Beam_handler(j),'XData',[x0 x1],'YData',[y0 y1],'Visible','on'); 33 | else 34 | set(EXP.Agent(n_robot).Sensor(n_sensor).Beam_handler(j),'XData',[],'YData',[],'Visible','on'); 35 | end 36 | end 37 | else 38 | for j=1:EXP.Agent(n_robot).Sensor(n_sensor).Number_of_measures 39 | set(EXP.Agent(n_robot).Sensor(n_sensor).Beam_handler(j),'Visible','off'); 40 | end 41 | end 42 | %------ 43 | end 44 | 45 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/move_to.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/Simulators/robot-sim/mars_install/Resources/move_to.m -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Resources/wrapToPi.m: -------------------------------------------------------------------------------- 1 | function [x] = wrapToPi(a) 2 | % Wraps angle in a, in radians, to the interval [-pi pi]. 3 | D=[a, a-2*pi, a+2*pi]; 4 | [out, ii] = min(abs(D)); 5 | x = D(ii); 6 | end 7 | -------------------------------------------------------------------------------- /Support files/Simulators/robot-sim/mars_install/Tasks/follow_behaviour.m: -------------------------------------------------------------------------------- 1 | function [Command, Exp_status]=follow_behaviour(Exp_status,Initialization,genotype,config) 2 | 3 | -------------------------------------------------------------------------------- /Support files/other/Activations/LeakyReLU.m: -------------------------------------------------------------------------------- 1 | function y = LeakyReLU(x) 2 | %Leaky ReLu node 3 | y = 0.01*x; 4 | y(x > 0) = x(x > 0); -------------------------------------------------------------------------------- /Support files/other/Activations/RBF.m: -------------------------------------------------------------------------------- 1 | function Y = RBF(X,Beta,w) 2 | 3 | Y = exp(-Beta.*norm(X - w).^2); 4 | 5 | -------------------------------------------------------------------------------- /Support files/other/Activations/ReLU.m: -------------------------------------------------------------------------------- 1 | function y = ReLU(x) 2 | %ReLu node 3 | y = zeros(size(x)); 4 | y(x > 0) = x(x > 0); 5 | 6 | -------------------------------------------------------------------------------- /Support files/other/Activations/binary.m: -------------------------------------------------------------------------------- 1 | function y = binary(x) 2 | 3 | y = double(x > 0); -------------------------------------------------------------------------------- /Support files/other/Activations/eLU.m: -------------------------------------------------------------------------------- 1 | function y = eLU(x,a) 2 | %exponential linear unit 3 | y=x; 4 | y(x > 0) = a*(exp(x(x > 0))-1); 5 | -------------------------------------------------------------------------------- /Support files/other/Activations/findActiv.m: -------------------------------------------------------------------------------- 1 | function [index] = findActiv(individualFcn,activ) 2 | 3 | for i = 1:length(individualFcn) 4 | index(i) = isequal(activ, individualFcn{i}); 5 | end 6 | 7 | index = find(index); -------------------------------------------------------------------------------- /Support files/other/Activations/gaussDist.m: -------------------------------------------------------------------------------- 1 | function f = gaussDist(x, mu, s) 2 | 3 | if nargin < 2 4 | mu = 0; 5 | s = 1; 6 | end 7 | 8 | p1 = -.5 * ((x - mu)/s) .^ 2; 9 | p2 = (s * sqrt(2*pi)); 10 | f = exp(p1) ./ p2; -------------------------------------------------------------------------------- /Support files/other/Activations/linearNode.m: -------------------------------------------------------------------------------- 1 | function y = linearNode(x) 2 | 3 | y= x; -------------------------------------------------------------------------------- /Support files/other/Activations/logistic.m: -------------------------------------------------------------------------------- 1 | function [Y] = logistic(X) 2 | 3 | Y = 1./(1+exp(-X)); 4 | 5 | end 6 | 7 | -------------------------------------------------------------------------------- /Support files/other/Activations/mackeyGlassNode.m: -------------------------------------------------------------------------------- 1 | 2 | function y = mackeyGlassNode(x) 3 | 4 | y = 0.4 * (x./(1+x.^1)); 5 | 6 | -------------------------------------------------------------------------------- /Support files/other/Activations/paraReLU.m: -------------------------------------------------------------------------------- 1 | function y = paraReLU(x,leakRate) 2 | %Parametric ReLu node 3 | y=x; 4 | y(x > 0) = leakRate*x(x > 0); 5 | -------------------------------------------------------------------------------- /Support files/other/Activations/sawtooth.m: -------------------------------------------------------------------------------- 1 | function y = sawtooth(x) 2 | 3 | y = mod(x,1); -------------------------------------------------------------------------------- /Support files/other/Activations/sin2.m: -------------------------------------------------------------------------------- 1 | function [Y] = sin2(X) 2 | 3 | Y = sin(X).*sin(X); 4 | 5 | end 6 | -------------------------------------------------------------------------------- /Support files/other/Activations/softplus.m: -------------------------------------------------------------------------------- 1 | function y = softplus(x) 2 | %analytical function 3 | y = log(1+exp(x)); -------------------------------------------------------------------------------- /Support files/other/Activations/symFcn.m: -------------------------------------------------------------------------------- 1 | function y = symFcn(x) 2 | 3 | y = 1-abs(x); -------------------------------------------------------------------------------- /Support files/other/Activations/types of activations available in matlab.txt: -------------------------------------------------------------------------------- 1 | 2 | % radial basis functions in MATLAB 3 | > radbas(n): Radial basis transfer function 4 | > radbasn(n) Normalised radial basis transfer function 5 | > tribas(n): Triangular basis transfer function -------------------------------------------------------------------------------- /Support files/other/Conversion func/array2binStr.m: -------------------------------------------------------------------------------- 1 | function y = array2binStr(x,signed,word_length,frac_length) 2 | 3 | y = []; 4 | 5 | for i = 1:size(x,1) 6 | t=[]; 7 | for j = 1:size(x,2) 8 | t = [t mat2str(x(i,j))]; 9 | end 10 | y(i) = typecast(uint16(bin2dec(t)),'int16'); 11 | end 12 | 13 | -------------------------------------------------------------------------------- /Support files/other/Conversion func/bin2num2.m: -------------------------------------------------------------------------------- 1 | function num = bin2num(bin,precision,endian) 2 | %bin2num - Convert from binary float in string to number 3 | % Converts from binary32 or binary64 IEEE 754 standards to number. 4 | % Pass 'single' for 32 or 'double' for 64 precision, 5 | % and 'Big' to Big-endian or 'Little' to Little-endian convention. 6 | % 7 | % Syntax: num = bin2num(s) 8 | % num = bin2num(s,precision,endian) 9 | % 10 | % Inputs: 11 | % bin - binary float string 12 | % precision - 'single' (default) or 'double' precision 13 | % endian - endianness convention 'Big' (default) or 'Little' 14 | % 15 | % Outputs: 16 | % num - matlab number 17 | % 18 | % 19 | % See also: num2bin, bin2dec, base2dec. 20 | % Author: Marco Borges, Ph.D. Student, Computer/Biomedical Engineer 21 | % UFMG, PPGEE, Neurodinamica Lab, Brazil 22 | % email address: marcoafborges@gmail.com 23 | % Website: http://www.cpdee.ufmg.br/ 24 | % April 2015; Version: v1; Last revision: 2015-04-28 25 | % Changelog: 26 | %------------------------------- BEGIN CODE ------------------------------- 27 | if nargin < 2 28 | endian = 'Big'; 29 | precision = 'single'; 30 | elseif nargin < 3 31 | endian = 'Big'; 32 | end 33 | r = rem(length(bin),4); 34 | if r > 0 35 | bin = [48*ones(1,4-r),bin]; 36 | end 37 | n = length(bin)/4; 38 | switch precision 39 | case 'single' 40 | if strcmp(endian,'Little') 41 | warning('TODO'); 42 | end 43 | b = hex2dec(dec2hex(bin2dec(reshape(bin,4,n)'))'); 44 | sign = bitget(b,32); 45 | exponent = bitget(b,24:31)*2.^(0:7).'; 46 | fraction = bitget(b,1:23)*2.^(-23:-1).'; 47 | num = (-1)^sign*(1+fraction)*2^(exponent-127); 48 | case 'double' 49 | if strcmp(endian,'Little') 50 | warning('TODO'); 51 | end 52 | num = hex2num(dec2hex(bin2dec(reshape(bin,4,n)'))'); 53 | end 54 | end 55 | %-------------------------------- END CODE -------------------------------- -------------------------------------------------------------------------------- /Support files/other/Conversion func/binStr2Array.m: -------------------------------------------------------------------------------- 1 | function y = binStr2Array(x) 2 | 3 | y=zeros(size(x)); 4 | for i = 1:size(x,1) 5 | for j = 1:size(x,2) 6 | y(i,j) = str2double(x(i,j)); 7 | end 8 | end 9 | 10 | y(:,isnan(y(1,:))) = []; -------------------------------------------------------------------------------- /Support files/other/Conversion func/binaryVector2doubleOutput.m: -------------------------------------------------------------------------------- 1 | %% Convert discrete (binary) data back to continuous (double) data 2 | function y = binaryVector2doubleOutput(x,q,nbits) 3 | 4 | if nargin < 2 5 | nbits = 16; %bit precision 6 | q = quantizer('fixed', 'Ceiling', 'Saturate', [nbits nbits-1]); 7 | end 8 | 9 | % convert double array to string 10 | s = num2str(x); 11 | 12 | % remove white spaces 13 | s(:,isspace(s(1,:))) =[]; 14 | 15 | % counter 16 | counter=1; 17 | 18 | % takes double convert to char binary 19 | for i = 1:nbits:size(x,2) 20 | y(:,counter) = bin2num(q,s(:,i:nbits*counter)); 21 | counter = counter+1; 22 | end -------------------------------------------------------------------------------- /Support files/other/Conversion func/dec2discreteInputVector.m: -------------------------------------------------------------------------------- 1 | %% convert a decimal into a disctrete binary vector 2 | % x = value 3 | % s = signed property 4 | % w = n-bit word length 5 | % f = fraction length 6 | 7 | function y = dec2discreteInputVector(x,s,w,f) 8 | 9 | if nargin < 2 10 | data = fi(x); %returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length when v is a double. 11 | else 12 | data = fi(x,s,w,f); % returns a fixed-point object with value v, Signed property value s, word length w, and fraction length f. Fraction length can be greater than word length or negative 13 | end 14 | binary_form = bin(data); 15 | 16 | %convert to input array 17 | y = binStr2Array(binary_form); 18 | 19 | %remove leftover NaNs 20 | y(:,isnan(y(1,:))) = []; 21 | -------------------------------------------------------------------------------- /Support files/other/Conversion func/double2binaryInputVector.m: -------------------------------------------------------------------------------- 1 | %% Convert continuous input data to discrete data 2 | function [y, q] = double2binaryInputVector(x,nbits) 3 | 4 | if nargin < 2 5 | nbits = 16; %bit precision 6 | end 7 | 8 | q = quantizer('fixed', 'Ceiling', 'Saturate', [nbits nbits-1]); 9 | 10 | % counter 11 | counter=1; 12 | 13 | % takes double, convert to char binary vector 14 | for i = 1:nbits:size(x,2)*nbits 15 | B(:,i:nbits*counter) = num2bin(q,x(:,counter)); 16 | counter = counter+1; 17 | end 18 | 19 | % binary char to double array 20 | y = binStr2Array(B); 21 | -------------------------------------------------------------------------------- /Support files/other/Database Search Methods/PSO.m: -------------------------------------------------------------------------------- 1 | %% Find best performances based on metrics using PSO 2 | function [final_error, final_metrics,output,video] = PSO(rngstate,metrics,test_error,metric_focus,task_num,swarm_size,maxStall,maxIter,minValue,multitask, video) 3 | 4 | rng(rngstate,'twister') 5 | 6 | if nargin > 10 7 | record = 1; 8 | 9 | else 10 | record = 0; 11 | video = 0; 12 | end 13 | 14 | %call func 15 | nvars = length(metric_focus); 16 | 17 | if multitask 18 | fun = @(x) getMultiError(x); 19 | else 20 | fun = @(x) getError(x); 21 | end 22 | 23 | options = optimoptions('particleswarm','SwarmSize',swarm_size,'MaxStallIterations',... 24 | maxStall,'MaxIterations',maxIter,'Display','off','InertiaRange',[0.2, 0.2],... 25 | 'SelfAdjustmentWeight',1.49,'SocialAdjustmentWeight',1.49,'PlotFcn',@pswplotswarm,'MinNeighborsFraction',1,'ObjectiveLimit',minValue);%,'OutputFcn',@pswplotranges); 26 | lb = min(metrics(:,metric_focus)); 27 | hb =max(metrics(:,metric_focus)); 28 | cnt = 1; 29 | [final_metrics,final_error,~,output] = particleswarm(fun,nvars,lb,hb,options); 30 | 31 | function y = getError(x) 32 | distances = pdist2(metrics(:,metric_focus),x); 33 | [~,indx] = min(distances); 34 | y = test_error(indx,task_num); 35 | end 36 | 37 | function y = getMultiError(x) 38 | distances = pdist2(metrics(:,metric_focus),x); 39 | [~,indx] = min(distances); 40 | y = sum(test_error(indx,:)); %all tasks 41 | end 42 | 43 | function stop = pswplotswarm(optimValues,state) 44 | stop = false; % This function does not stop the solver 45 | s = optimValues.swarm; 46 | scatter(metrics(:,metric_focus(1)),metrics(:,metric_focus(2)),10,[0.75 0.75 0.75]) 47 | hold on 48 | scatter(s(:,1),s(:,2),20,log(optimValues.swarmfvals),'filled') 49 | hold off 50 | colormap('copper') 51 | colorbar 52 | %drawnow 53 | if record 54 | F(cnt) = getframe; 55 | writeVideo(video,F(cnt)); 56 | cnt = cnt+1; 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /Support files/other/Database Search Methods/runPSOsearch.m: -------------------------------------------------------------------------------- 1 | %% set parameters for tasks 2 | config.rngState = 1; 3 | config.task_list = {'narma_10'}; % assign tasks. Can be multiple, e.g. config.taskList ={'NARMA10', 'Laser', 'Iris'};, etc. 4 | config.error_to_check = 'train&val&test'; 5 | 6 | config.compare_to_rand_search = 0; % if wanting to compare PSO to rand search 7 | 8 | %% PSO and parameters 9 | config.swarm_size = 10; 10 | config.maxStall = 15; 11 | config.maxIter = 50; 12 | 13 | config.InertiaRange = [0.1, 1.1]; 14 | config.SelfAdjustmentWeight = 1.49; 15 | config.SocialAdjustmentWeight = 1.49; 16 | config.MinNeigh = 0.25; 17 | 18 | all_behaviours = reshape([database.behaviours],length(database(1).behaviours),length(database))'; 19 | [final_error, final_metrics, best_indv, output] = psoOnDatabase(config,all_behaviours,database); 20 | 21 | if config.compare_to_rand_search 22 | %% get task errors for all in the database - needed for random search 23 | all_behaviours = reshape([database.behaviours],length(database(1).behaviours),length(database))'; 24 | task_error = assessDBonTasks(config,database,all_behaviours); 25 | 26 | %% Equivalent random search 27 | num_rand = output.funccount; 28 | indx = randi([1 length(database)],num_rand,1); 29 | rand_search = task_error.outputs(indx); 30 | best_rand = min(rand_search); 31 | end -------------------------------------------------------------------------------- /Support files/other/Database Search Methods/searchDatabase.m: -------------------------------------------------------------------------------- 1 | 2 | function [final_error, final_metrics,output] = searchDatabase(config,database,genotype) 3 | 4 | rng(config.rngState,'twister'); 5 | 6 | fun = @(x) getError(x); 7 | 8 | x0 = length(database); 9 | 10 | options = optimoptions('fminunc','Algorithm','quasi-newton'); 11 | 12 | options.Display = 'iter'; 13 | 14 | [final_metrics, final_error, ~, output] = fminunc(fun,x0,options); 15 | 16 | function y = getError(x) 17 | %distances = pdist2(database,x);%[round(x(1)) x(2)]); 18 | %[~,indx] = min(distances); 19 | indx = round(x); 20 | 21 | %evaluate ESN on task 22 | task_error = assessDBonTasks(config,genotype(indx),database(indx,:)); 23 | 24 | y = task_error.outputs; 25 | end 26 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/CML.m: -------------------------------------------------------------------------------- 1 | function [x] = CML(individual, input_sequence, config) 2 | 3 | switch(config.type) 4 | 5 | case 'CML' % coupled map lattice 6 | x = [1 individual.x0 1]; 7 | for n = 1:config.time_steps 8 | x(n+1,2:end-1) = (1 - individual.W').*f(x(n,2:end-1)) + (individual.W'/2).*(f(x(n,3:end)) + f(x(n,1:end-2)));% + individual.Win'*input_sequence(n,:); 9 | end 10 | 11 | case 'GCM' % globally coupled map 12 | x = individual.x0; 13 | for n = 1:config.time_steps 14 | x(n+1,:) = (1 - individual.W').*f(x(n,:)) + (individual.W'/individual.lattice_size)*sum(f(x(n,:))); 15 | end 16 | end 17 | 18 | 19 | imagesc(x') 20 | drawnow 21 | 22 | % logistic map function 23 | function x = f(x) 24 | x = 1-individual.r*x.^2; 25 | end 26 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/F1Score.m: -------------------------------------------------------------------------------- 1 | function [mean_score, order ] = F1Score(targ,predic) 2 | %F1SCORE 3 | [input_matrix, order] = confusionmat(targ,predic); 4 | % Compute F1 score by using precision and recall 5 | score = 2*(precision(input_matrix).*recall(input_matrix))./(precision(input_matrix)+recall(input_matrix)); 6 | score(isnan(score)) = 1; 7 | mean_score = mean(score); 8 | 9 | end 10 | 11 | function p = precision(M) 12 | p = diag(M) ./ sum(M,2); 13 | end 14 | 15 | function r = recall(M) 16 | r = diag(M) ./ sum(M,1)'; 17 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/JapaneseVowels/Test_Jap_vowels.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/JapaneseVowels/Test_Jap_vowels.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/JapaneseVowels/Train_Jap_vowels.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/JapaneseVowels/Train_Jap_vowels.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/JapaneseVowels/blockNo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/JapaneseVowels/blockNo.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/JapaneseVowels/blockNumbers.txt: -------------------------------------------------------------------------------- 1 | Train blocks 2 | 30 30 30 30 30 30 30 30 30 3 | 4 | Test blocks 5 | 31 35 88 44 29 24 40 50 29 -------------------------------------------------------------------------------- /Support files/other/Datasets/JapaneseVowels/readJapVowels.m: -------------------------------------------------------------------------------- 1 | %% Japanese Vowels: 2 | % - 9 speakers, 30 utterances with times series length 7-29 3 | function [Train_jap_vowels,train_outputSequence,Test_jap_vowels,test_outputSequence] = readJapVowels() 4 | 5 | load('Datasets/JapaneseVowels/Train_Jap_vowels.mat'); 6 | load('Datasets/JapaneseVowels/Test_Jap_vowels.mat'); 7 | load('Datasets/JapaneseVowels/blockNo.mat'); 8 | 9 | %load training set 10 | fileID = fopen('train.txt'); 11 | formatSpec = '%.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f'; 12 | block = 1; 13 | while ~feof(fileID) 14 | train(block,:)= textscan(fileID,formatSpec,'HeaderLines', 1,'Delimiter','\t'); 15 | block = block+1; 16 | end 17 | fclose(fileID); 18 | 19 | %load test set 20 | fileID = fopen('test.txt'); 21 | formatSpec = '%.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f'; 22 | block = 1; 23 | while ~feof(fileID) 24 | test(block,:)= textscan(fileID,formatSpec,'HeaderLines', 1,'Delimiter','\t'); 25 | block = block+1; 26 | end 27 | fclose(fileID); 28 | 29 | 30 | % Create train Output data 31 | for i = 1:270 32 | a = cell2mat(train(i,:)); 33 | listTrain(i)=size(a,1); 34 | end 35 | 36 | endsep =0; 37 | endlist =0; 38 | for i = 1:9 39 | startlist = endlist + 1; 40 | endlist = startlist-1 + blockNo(1,i); 41 | speakerTrain(i)=sum(listTrain(startlist:endlist)); 42 | 43 | start = endsep + 1; 44 | endsep = start-1 + speakerTrain(i); 45 | train_outputSequence(start:endsep,i) = 1; 46 | end 47 | 48 | % Create test Output data 49 | for i = 1:370 50 | b = cell2mat(test(i,:)); 51 | listTest(i)=size(b,1); 52 | end 53 | 54 | endsep =0; 55 | endlist =0; 56 | for i = 1:9 57 | startlist = endlist + 1; 58 | endlist = startlist-1 + blockNo(2,i); 59 | speakerTest(i)=sum(listTest(startlist:endlist)); 60 | 61 | start = endsep + 1; 62 | endsep = start-1 + speakerTest(i); 63 | test_outputSequence(start:endsep,i) = 1; 64 | end 65 | 66 | 67 | %% 68 | 69 | -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/loadMNISTImages.m: -------------------------------------------------------------------------------- 1 | function images = loadMNISTImages(filename) 2 | %loadMNISTImages returns a 28x28x[number of MNIST images] matrix containing 3 | %the raw MNIST images 4 | 5 | fp = fopen(filename, 'rb'); 6 | assert(fp ~= -1, ['Could not open ', filename, '']); 7 | 8 | magic = fread(fp, 1, 'int32', 0, 'ieee-be'); 9 | assert(magic == 2051, ['Bad magic number in ', filename, '']); 10 | 11 | numImages = fread(fp, 1, 'int32', 0, 'ieee-be'); 12 | numRows = fread(fp, 1, 'int32', 0, 'ieee-be'); 13 | numCols = fread(fp, 1, 'int32', 0, 'ieee-be'); 14 | 15 | images = fread(fp, inf, 'unsigned char'); 16 | images = reshape(images, numCols, numRows, numImages); 17 | images = permute(images,[2 1 3]); 18 | 19 | fclose(fp); 20 | 21 | % Reshape to #pixels x #examples 22 | images = reshape(images, size(images, 1) * size(images, 2), size(images, 3)); 23 | % Convert to double and rescale to [0,1] 24 | images = double(images) / 255; 25 | 26 | end 27 | -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/loadMNISTLabels.m: -------------------------------------------------------------------------------- 1 | function labels = loadMNISTLabels(filename) 2 | %loadMNISTLabels returns a [number of MNIST images]x1 matrix containing 3 | %the labels for the MNIST images 4 | 5 | fp = fopen(filename, 'rb'); 6 | assert(fp ~= -1, ['Could not open ', filename, '']); 7 | 8 | magic = fread(fp, 1, 'int32', 0, 'ieee-be'); 9 | assert(magic == 2049, ['Bad magic number in ', filename, '']); 10 | 11 | numLabels = fread(fp, 1, 'int32', 0, 'ieee-be'); 12 | 13 | labels = fread(fp, inf, 'unsigned char'); 14 | 15 | assert(size(labels,1) == numLabels, 'Mismatch in label count'); 16 | 17 | fclose(fp); 18 | 19 | end 20 | -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/t10k-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/MNIST/t10k-images.idx3-ubyte -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/train-images-idx3-ubyte.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/MNIST/train-images-idx3-ubyte.gz -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/train-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/MNIST/train-images.idx3-ubyte -------------------------------------------------------------------------------- /Support files/other/Datasets/MNIST/train-labels.idx1-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/MNIST/train-labels.idx1-ubyte -------------------------------------------------------------------------------- /Support files/other/Datasets/NS_training_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/NS_training_data.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/NonLinear_ChanEQ_data.m: -------------------------------------------------------------------------------- 1 | function [inputSequence, outputSequence] = NonLinear_ChanEQ_data(dataLength) 2 | 3 | choose = [-3 -1 1 3]; 4 | 5 | for i = 1:dataLength+2 6 | d(i) = choose(randi([1 4])); 7 | end 8 | 9 | 10 | for i = 8:dataLength 11 | q(i)= 0.08*d(i+2) - 0.12*d(i+1) + d(i) + 0.18*d(i-1) - 0.1*d(i-2) + 0.091*d(i-3) - 0.05*d(i-4) + 0.04*d(i-5) +0.03*d(i-6) +0.01*d(i-7); 12 | u(i) = q(i)+0.036*(q(i).^2) - 0.011*(q(i).^3); 13 | end 14 | 15 | % inputSequence(1,:) = awgn(u,12,'measured'); 16 | % inputSequence(2,:) = awgn(u,16,'measured'); 17 | % inputSequence(3,:) = awgn(u,20,'measured'); 18 | % inputSequence(4,:) = awgn(u,24,'measured'); 19 | % inputSequence(5,:) = awgn(u,28,'measured'); 20 | % inputSequence(6,:) = awgn(u,32,'measured'); 21 | inputSequence = u+30; 22 | 23 | outputSequence = [0 0 d(1:dataLength-2)]; 24 | 25 | 26 | %remove if not working 27 | % for i = 1:size(inputSequence,1) 28 | % inputSequence(i,:) = (inputSequence(i,:)-mean(inputSequence(i,:)))/(max(inputSequence(i,:))-min(inputSequence(i,:))); 29 | % end 30 | 31 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/attractorSwitch.m: -------------------------------------------------------------------------------- 1 | 2 | function [out] = attractorSwitch(data_length,num_attractors,to_plot) 3 | 4 | rng(1,'twister') 5 | out = []; 6 | t = linspace(-10,10,data_length/num_attractors); 7 | out(:,1) = sin(t*2*pi) + 2*rand*cos(t*2*pi)-1; 8 | out(:,2) = cos(t*2*pi) + 2*rand*sin(t*2*pi)-1; 9 | 10 | for i = 1:num_attractors-1 11 | ex = [2*rand*sin(t*2*pi) + randi([-8 8]);... 12 | 2*rand*cos(t*2*pi) + randi([-8 8])]'; 13 | out = [out; ex]; 14 | end 15 | 16 | if to_plot 17 | tail = 50; 18 | for k = tail+1:10:length(out)-1 19 | plot(out(k-tail:k,1),out(k-tail:k,2)) 20 | xlim([-10 10]) 21 | ylim([-10 10]) 22 | drawnow 23 | end 24 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/compareIPIXfigure.m: -------------------------------------------------------------------------------- 1 | function compareIPIXfigure(Y1, figHandle) 2 | %CREATEFIGURE(Y1) 3 | % Y1: vector of y data 4 | %Y1 = trainError(1,[1 3 5 7 9]).^2; 5 | % Auto-generated by MATLAB on 14-Feb-2017 17:04:24 6 | 7 | % Create figure 8 | figure(figHandle); 9 | clf(figHandle); 10 | % Create axes 11 | axes1 = axes('Parent',figHandle,'YGrid','on','YScale','log'); 12 | box(axes1,'on'); 13 | hold(axes1,'on'); 14 | 15 | % Create semilogy 16 | hold on; 17 | semilogy([1 5],[0.00115 0.0301],'DisplayName','Rodan & Tino. 2010.','Marker','diamond','LineStyle','none'); 18 | semilogy(1:10,[0.0015 0.003 0.006 0.0115 0.017 0.025 0.035 0.049 0.062 0.08 ],'DisplayName','Duport et al. 2012','Marker','diamond','LineStyle','none'); 19 | semilogy(1:10,[0.0045 0.012 0.025 0.05 0.075 0.12 0.18 0.22 0.29 0.36],'DisplayName','Duport et al. 2016','Marker','diamond','LineStyle','none'); 20 | 21 | for i = 1:size(Y1,1) 22 | semilogy(Y1(i,21:30),'DisplayName',strcat('Material_',num2str(i)),'Marker','diamond','LineStyle','none'); 23 | end 24 | hold off; 25 | 26 | % Create legend 27 | %legend(axes1,'Rodan & Tino. 2010.','Duport et al. 2012','Duport et al. 2016','Avg best reser') 28 | legend(axes1,'show'); -------------------------------------------------------------------------------- /Support files/other/Datasets/coupledLogisticMaps.m: -------------------------------------------------------------------------------- 1 | %% Coupled Logistic Maps 2 | function coupledLogisticMaps(x0,a,b,b_range) 3 | % Input variables: 4 | % initial conditions = x0 5 | % parameter = a 6 | % coupling parameter = b 7 | % range to plot bifurcation diagram = b_range 8 | % 9 | % Examples: 10 | % Spiral -- Phase portraits: x = 0.68, y = 0.66, a = 2, b = 0.68 --> Bifurcation diagram: b = 0:0.01:1 11 | % coupledLogisticMaps([0.68 0.66],2,0.68,0:0.01:1) 12 | % 13 | % Four circles -- Phase portraits: x = 0.68, y = 0.66, a = 3.432, b = -0.3 --> Bifurcation diagram: b = -0.3:0.01:0 14 | % coupledLogisticMaps([0.68 0.66],3.432,-0.3,-0.3:0.01:0) 15 | % 16 | % Ring -- Phase portraits: x = 0.84, y = 0.43, a = 3.6, b = -0.3 --> Bifurcation diagram: b = -0.1:0.001:0.01 17 | % coupledLogisticMaps([0.84 0.43],3.6,-0.069,-0.1:0.001:0.01) 18 | 19 | time_steps = 200; 20 | x = x0(1); 21 | y = x0(2); 22 | 23 | % run coupled lattice 24 | for i = 1:time_steps 25 | x(i+1,:) = a*y(i,:)*(1-y(i,:)) + b*(x(i,:) -y(i,:)); 26 | y(i+1,:) = a*x(i,:)*(1-x(i,:)) + b*(y(i,:) -x(i,:)); 27 | end 28 | 29 | subplot(1,2,1) 30 | scatter(x,y,'.') 31 | title('Phase portrait') 32 | 33 | %% bifurcation diagram 34 | b = b_range; 35 | c_b = []; c_x =[]; 36 | time_steps = 200; 37 | 38 | % collect states of coupled lattice 39 | for i = 1:length(b)-1 40 | for j = 1:time_steps 41 | x(j+1) = a*y(j)*(1-y(j)) + b(i)*(x(j) -y(j)); 42 | y(j+1) = a*x(j)*(1-x(j)) + b(i)*(y(j) -x(j)); 43 | c_b(j,i) = b(i); 44 | end 45 | c_b(j+1,i)= b(i); 46 | c_x(:,i) = x(1:end); 47 | end 48 | 49 | c_b = c_b(100:end,:); 50 | c_x = c_x(100:end,:); 51 | subplot(1,2,2) 52 | scatter(c_b(:),c_x(:),'.') 53 | title('Bifurcation diagram') -------------------------------------------------------------------------------- /Support files/other/Datasets/createDuffingOscillator.m: -------------------------------------------------------------------------------- 1 | function [out] =createDuffingOscillator(data_length, data_struct, y0, T) 2 | %This program in computed by S.Sabarathinam 3 | %%Based on: Nonlinear Dynamics: Integrability, Chaos and Patterns,by M Lakshmanan, S Rajaseekar 4 | % to see the double scroll chaotic attractor in this program 5 | %to change the 'amp' value you can see the period doubling scenario 6 | 7 | %time step and initial condition 8 | %tspan = 0:0.1:data_length*0.1; 9 | tspan = [0 data_length]; 10 | op=odeset('abstol',1e-9,'reltol',1e-9); 11 | %[t,y] = ode45(@(t,x) f(t,x,data_struct.delta,data_struct.alpha,data_struct.beta,data_struct.gamma,data_struct.w),tspan,y0,op); 12 | sol = ode45(@(t,x) f(t,x,data_struct.delta,data_struct.alpha,data_struct.beta,data_struct.gamma,data_struct.w),tspan,y0,op); 13 | t = linspace(0,T,data_length); 14 | y = deval(sol,t); 15 | 16 | x1=y(1,:); x2=y(2,:); 17 | subplot(1,2,1) 18 | plot(-x1(data_length*0.2+1:end),-x2(data_length*0.2+1:end)); %plot the variable x and y 19 | subplot(1,2,2) 20 | plot(-x1(data_length*0.2+1:end)) 21 | out = y; 22 | 23 | end 24 | 25 | function dy = f(t,y,delta,alpha,beta,gamma,w) 26 | x1 = y(1); x2 = y(2); 27 | dx1 = x2; 28 | dx2 = -delta*x2- alpha*x1- beta*x1^3+ gamma*sin(w*t); 29 | dy = [dx1; dx2]; 30 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/createIPIXfigure.m: -------------------------------------------------------------------------------- 1 | function createIPIXfigure(Y1, figHandle) 2 | %CREATEFIGURE(Y1) 3 | % Y1: vector of y data 4 | %Y1 = trainError(1,[1 3 5 7 9]).^2; 5 | % Auto-generated by MATLAB on 14-Feb-2017 17:04:24 6 | 7 | % Create figure 8 | figure(figHandle); 9 | clf(figHandle); 10 | % Create axes 11 | axes1 = axes('Parent',figHandle,'YGrid','on','YScale','log'); 12 | box(axes1,'on'); 13 | hold(axes1,'on'); 14 | 15 | % Create semilogy 16 | hold on; 17 | semilogy([1 5],[0.00115 0.0301],'DisplayName','Rodan & Tino. 2010.','Marker','diamond','LineStyle','none'); 18 | semilogy(1:10,[0.0015 0.003 0.006 0.0115 0.017 0.025 0.035 0.049 0.062 0.08 ],'DisplayName','Duport et al. 2012','Marker','diamond','LineStyle','none'); 19 | semilogy(1:10,[0.0045 0.012 0.025 0.05 0.075 0.12 0.18 0.22 0.29 0.36],'DisplayName','Duport et al. 2016','Marker','diamond','LineStyle','none'); 20 | if size(Y1,1) > 1 21 | boxplot(Y1,'PlotStyle','compact'); 22 | else 23 | semilogy(Y1,'DisplayName','Phys Res','Marker','diamond','LineStyle','none'); 24 | end 25 | hold off; 26 | 27 | % Create legend 28 | %legend(axes1,'Rodan & Tino. 2010.','Duport et al. 2012','Duport et al. 2016','Avg best reser') 29 | legend(axes1,'show'); -------------------------------------------------------------------------------- /Support files/other/Datasets/createLimitCycleAttractor.m: -------------------------------------------------------------------------------- 1 | function [x, y] = createLimitCycleAttractor(mu, T, h ,data_points) 2 | 3 | % initial value 4 | x0 = [1; 1]; 5 | 6 | % run 4th order Runge-Kutta 7 | [~,X] = rk4(@f,[0, T],x0,h); 8 | 9 | % ode45 method 10 | eps = 0.000001; 11 | options = odeset('RelTol',eps,'AbsTol',[eps eps]); 12 | sol = ode45(@f, 0:h:T, x0,options); 13 | t = linspace(0,T,data_points); 14 | X_ode = deval(sol,t)'; 15 | 16 | % plot attractor and compare 17 | subplot(1,2,1) 18 | plot(X(:,1),X(:,2)); 19 | subplot(1,2,2) 20 | plot(X_ode(:,1),X_ode(:,2)); 21 | axis equal; 22 | grid; 23 | title(strcat('Van der Pol oscillator: mu ',num2str(mu))); 24 | xlabel('X'); ylabel('Y'); 25 | 26 | x = X(:,1); 27 | y = X(:,2); 28 | 29 | function dx = f(T, X) 30 | % Evaluates the right hand side of the Van der Pol oscillator 31 | % x' = y 32 | % y' = mu*(1 - x^2)*y - x 33 | 34 | dx = zeros(2,1); 35 | dx(1) = X(2); 36 | dx(2) = mu*(1-X(1).^2)*X(2) - X(1); 37 | 38 | end 39 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/createLorenz.m: -------------------------------------------------------------------------------- 1 | function [x, y, z] = createLorenz(rho, sigma, beta, T, h, data_points) 2 | 3 | % LORENZ Function generates the lorenz attractor of the prescribed values 4 | % of parameters rho, sigma, beta 5 | % 6 | % [x,y,z] = LORENZ(RHO,SIGMA,BETA,T) 7 | % x, y, z - output vectors of the strange attactor trajectories 8 | % RHO - Rayleigh number 9 | % SIGMA - Prandtl number 10 | % BETA - parameter 11 | % T - time interval 12 | 13 | % Example. 14 | % [X Y Z] = lorenz(28, 10, 8/3); 15 | % plot3(X,Y,Z); 16 | 17 | if nargin<3 18 | error('MATLAB:lorenz:NotEnoughInputs','Not enough input arguments.'); 19 | end 20 | 21 | % initial value 22 | x0 = [1; 1; 1]; 23 | 24 | % % run 4th order Runge-Kutta 25 | % [~,X] = rk4(@f,[0, T],x0,h); 26 | 27 | % ode45 method 28 | eps = 0.000001; 29 | options = odeset('RelTol',eps,'AbsTol',[eps eps eps/10]); 30 | sol = ode45(@f, 0:h:T, x0,options); 31 | t = linspace(0,T,data_points); 32 | X_ode = deval(sol,t)'; 33 | 34 | % plot attractor and compare 35 | % subplot(1,2,1) 36 | % plot3(X(:,1),X(:,2),X(:,3)); 37 | % subplot(1,2,2) 38 | plot3(X_ode(:,1),X_ode(:,2),X_ode(:,3)); 39 | axis equal; 40 | grid; 41 | title('Lorenz attractor'); 42 | xlabel('X'); ylabel('Y'); zlabel('Z'); 43 | 44 | x = X_ode(:,1); 45 | y = X_ode(:,2); 46 | z = X_ode(:,3); 47 | 48 | function dx = f(T, X) 49 | % Evaluates the right hand side of the Lorenz system 50 | % x' = sigma*(y-x) 51 | % y' = x*(rho - z) - y 52 | % z' = x*y - beta*z 53 | % typical values: rho = 28; sigma = 10; beta = 8/3; 54 | dx = zeros(3,1); 55 | dx(1) = sigma*(X(2) - X(1)); 56 | dx(2) = X(1)*(rho - X(3)) - X(2); 57 | dx(3) = X(1)*X(2) - beta*X(3); 58 | end 59 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/createMackeyGlass.m: -------------------------------------------------------------------------------- 1 | function x = createMackeyGlass(tau, gamma, beta, p, T, data_points) 2 | 3 | % MackeyGlass Function generates the Mackey-Glass attractor of the prescribed values 4 | % of parameters tau, gamma, beta, p 5 | % 6 | % [x,y,z] = LORENZ(tau, gamma, beta, p, T, h) 7 | % x - output vectors of the MG attactor trajectories 8 | % tau - delay 9 | % gamma - current state multiplier 10 | % beta - delay multiplier 11 | % p - exponent 12 | % T - time interval 13 | % h - integration time step 14 | 15 | % Example. 16 | % [x] = createMackeyGlass(17, 0.1, 0.2, 10, [0 1000]); 17 | % plot(x); 18 | 19 | if nargin<3 20 | error('MATLAB:lorenz:NotEnoughInputs','Not enough input arguments.'); 21 | end 22 | 23 | % dde23 method 24 | sol = dde23(@f,tau,0.5,[0, T]); 25 | t = linspace(tau,T,data_points); 26 | x = deval(sol,t); 27 | plot(x); 28 | title('MG attractor'); 29 | xlabel('t'); ylabel(''); 30 | 31 | 32 | function dxdt = f(t,x,Z) 33 | dxdt = (beta*Z)/(1 + Z^p) - gamma*x; 34 | 35 | end 36 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/createRosslerAttractor.m: -------------------------------------------------------------------------------- 1 | function [x, y,z] = createRosslerAttractor(a,b,c, T, h, data_points) 2 | 3 | % initial value 4 | x0 = [1; 1; 1]; 5 | 6 | % run 4th order Runge-Kutta 7 | [~,X] = rk4(@f,[0, T],x0,h); 8 | 9 | % ode45 method 10 | eps = 0.000001; 11 | options = odeset('RelTol',eps,'AbsTol',[eps eps eps/10]); 12 | sol = ode45(@f, 0:h:T, x0,options); 13 | t = linspace(0,T,data_points); 14 | X_ode = deval(sol,t)'; 15 | 16 | % plot attractor and compare 17 | subplot(1,2,1) 18 | plot3(X(:,1),X(:,2),X(:,3)); 19 | subplot(1,2,2) 20 | plot3(X_ode(:,1),X_ode(:,2),X_ode(:,3)); 21 | axis equal; 22 | grid; 23 | title('Rossler attractor'); 24 | xlabel('X'); ylabel('Y'); zlabel('Z'); 25 | 26 | x = X(:,1); 27 | y = X(:,2); 28 | z = X(:,3); 29 | 30 | function dx = f(T, X) 31 | % Evaluates the right hand side of the Lorenz system 32 | % x' = -y-z 33 | % y' = x + ay 34 | % z' = b + z(x-c) 35 | % typical values: a = 0.2; b = 0.2; c = 5.7; or a = 0.1; b = 0.1; c = 14 36 | dx = zeros(3,1); 37 | dx(1) = -X(2) - X(3); 38 | dx(2) = X(1) + a*X(2); 39 | dx(3) = b + X(3)*(X(1)-c); 40 | end 41 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/displayMemNonlinMap.m: -------------------------------------------------------------------------------- 1 | function [plt] = displayMemNonlinMap(figureHandle,saveError,tests,set) 2 | 3 | num = 1; 4 | switch(set) 5 | case 'train' 6 | setNum = 0; 7 | case 'val' 8 | setNum = 150; 9 | case 'test' 10 | setNum = 300; 11 | case 'both' 12 | %get train 13 | setNum = 0; 14 | for d = 1:15 15 | for p = 1:10 16 | plt(d,p) = saveError(tests,setNum+num); 17 | num = num+1; 18 | end 19 | end 20 | %repeat for val 21 | setNum = 150; 22 | num = 1; 23 | for d = 1:15 24 | for p = 1:10 25 | plt1(d,p) = saveError(tests,setNum+num); 26 | num = num+1; 27 | end 28 | end 29 | 30 | figure(figureHandle); 31 | subplot(2,2,1) 32 | contour(plt','ShowText','on') 33 | title('Memory and Nonlinear Mapping: Training'); 34 | ylabel('Nonlinearity') 35 | xlabel('Delay') 36 | 37 | figure(figureHandle); 38 | subplot(2,2,2) 39 | contour(plt1','ShowText','on') 40 | title('Memory and Nonlinear Mapping: Test'); 41 | ylabel('Nonlinearity') 42 | xlabel('Delay') 43 | 44 | subplot(2,2,[3 4]) 45 | surfc(plt'-plt1') 46 | title('Train -- Test'); 47 | ylabel('Nonlinearity') 48 | xlabel('Delay') 49 | zlabel('Error') 50 | end 51 | 52 | if strcmp(set, 'both') == 0 53 | for d = 1:15 54 | for p = 1:10 55 | plt(d,p) = saveError(tests,setNum+num); 56 | num = num+1; 57 | end 58 | end 59 | 60 | figure(figureHandle); 61 | subplot(1,2,1) 62 | contour(plt','ShowText','on') 63 | title('Memory and Nonlinear Mapping'); 64 | ylabel('Nonlinearity') 65 | xlabel('Delay') 66 | 67 | subplot(1,2,2) 68 | surfc(plt') 69 | title('Memory and Nonlinear Mapping'); 70 | ylabel('Nonlinearity') 71 | xlabel('Delay') 72 | zlabel('Error') 73 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/featureNormailse.m: -------------------------------------------------------------------------------- 1 | function [Y] = featureNormailse(X,Type) 2 | 3 | %Number of observations 4 | N=length(X(:,1)); 5 | 6 | %Number of variables 7 | M=length(X(1,:)); 8 | 9 | % output array of normalised values 10 | Y=zeros(N,M); 11 | 12 | switch Type 13 | 14 | case'std' 15 | %Subtract mean of each Column from data 16 | Y=X-repmat(mean(X),N,1); 17 | 18 | %normalize each observation by the standard deviation of that variable 19 | Y=Y./repmat(std(X,0,1),N,1); 20 | 21 | case 'scaling' % scal each column/feature to be within [0 1] 22 | % determine the maximum value of each colunm of an array 23 | Max=max(X); 24 | % determine the minimum value of each colunm of an array 25 | Min=min(X); 26 | %array that contains the different between the maximum and minimum value for each column 27 | Difference=Max-Min; 28 | %subtract the minimum value for each column 29 | Y=X-repmat(Min,N,1); 30 | %Column by the difference between the maximum and minimum value 31 | Y=Y./repmat(Difference,N,1); 32 | 33 | Y = 2*Y-1; %shift to [-1 1] 34 | 35 | case 'rescale' % all scaled together within [0 1] 36 | Y =(X-min(min(X)))./(max(max(X))-min(min(X))); 37 | Y = 2*Y-1; %shift to [-1 1] 38 | %Y = X*1e21;%2*Y-1; %shift to [-1 1] 39 | 40 | otherwise 41 | Y = X; 42 | end 43 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/featureNormalize.m: -------------------------------------------------------------------------------- 1 | function [X_norm, mu, sigma] = featureNormalize(X) 2 | %FEATURENORMALIZE Normalizes the features in X 3 | % FEATURENORMALIZE(X) returns a normalized version of X where 4 | % the mean value of each feature is 0 and the standard deviation 5 | % is 1. This is often a good preprocessing step to do when 6 | % working with learning algorithms. 7 | 8 | mu = mean(X); 9 | X_norm = bsxfun(@minus, X, mu); 10 | 11 | sigma = std(X_norm); 12 | X_norm = bsxfun(@rdivide, X_norm, sigma); 13 | 14 | 15 | % ============================================================ 16 | 17 | end 18 | -------------------------------------------------------------------------------- /Support files/other/Datasets/franke2d.m: -------------------------------------------------------------------------------- 1 | function [y] = franke2d(x1,x2) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | % 5 | % FRANKE'S FUNCTION 6 | % 7 | % Authors: Sonja Surjanovic, Simon Fraser University 8 | % Derek Bingham, Simon Fraser University 9 | % Questions/Comments: Please email Derek Bingham at dbingham@stat.sfu.ca. 10 | % 11 | % Copyright 2013. Derek Bingham, Simon Fraser University. 12 | % 13 | % THERE IS NO WARRANTY, EXPRESS OR IMPLIED. WE DO NOT ASSUME ANY LIABILITY 14 | % FOR THE USE OF THIS SOFTWARE. If software is modified to produce 15 | % derivative works, such modified software should be clearly marked. 16 | % Additionally, this program is free software; you can redistribute it 17 | % and/or modify it under the terms of the GNU General Public License as 18 | % published by the Free Software Foundation; version 2.0 of the License. 19 | % Accordingly, this program is distributed in the hope that it will be 20 | % useful, but WITHOUT ANY WARRANTY; without even the implied warranty 21 | % of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | % General Public License for more details. 23 | % 24 | % For function details and reference information, see: 25 | % http://www.sfu.ca/~ssurjano/ 26 | % 27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 28 | % 29 | % INPUT: 30 | % 31 | % xx = [x1, x2] 32 | % 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | 35 | %x1 = xx(1); 36 | %x2 = xx(2); 37 | 38 | term1 = 0.75 .* exp(-(9.*x1-2).^2./4 - (9.*x2-2).^2./4); 39 | term2 = 0.75 .* exp(-(9.*x1+1).^2/.49 - (9.*x2+1)./10); 40 | term3 = 0.5 .* exp(-(9.*x1-7).^2./4 - (9.*x2-3).^2./4); 41 | term4 = -0.2 .* exp(-(9.*x1-4).^2 - (9.*x2-7).^2); 42 | 43 | y = term1 + term2 + term3 + term4; 44 | 45 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/generateHenonMap.m: -------------------------------------------------------------------------------- 1 | function [input,output] = generateHenonMap(dataLength, stdev) 2 | 3 | i=1; 4 | while(1) 5 | rng(i,'twister'); 6 | 7 | noise = stdev*randn(dataLength,1); 8 | %noise = stdev*rand(dataLength,1);% taken from "A Comparative Study of Reservoir Computing... 9 | ...for Temporal Signal Processing (Goudarzi,2015)" 10 | 11 | y = zeros(dataLength,1); 12 | 13 | 14 | for i = 3:dataLength-1 15 | %y(i) = 1-(1.4*(y(i-1).^2)) + (0.3*y(i-2)); 16 | 17 | y(i) = 1-((1.4)*(y(i-1).^2)) + (0.3*y(i-2));% + stdev*randn; 18 | % x(i+1)=1-1.4*x(i).^2 + y(i); 19 | % y(i+1)=0.3*x(i);%+ noise(i+1); 20 | %y(i+1)= (y(i+1)-0.5)*2; 21 | end 22 | 23 | y = ((y+noise)-0.5)*2; 24 | 25 | input = [0; y(1:dataLength-1)]; 26 | output = y; 27 | if isinf(output(end-1)) 28 | i = i+1; 29 | else 30 | break 31 | end 32 | end 33 | 34 | % figure 35 | % scatter(input,output) -------------------------------------------------------------------------------- /Support files/other/Datasets/getAdderTruthTable.m: -------------------------------------------------------------------------------- 1 | %% Create binary adder truth table 2 | function truth_table = getAdderTruthTable(type,input) 3 | 4 | switch(type) 5 | 6 | case 'half_adder' 7 | % half adder 8 | output = []; 9 | %input = de2bi(0:3,'left-msb'); 10 | [output(:,1), output(:,2)] = half_adder(input(:,1),input(:,2)); 11 | truth_table = [input output]; 12 | 13 | case 'full_adder' 14 | % full adder 15 | output = []; 16 | %input = de2bi(0:7,'left-msb'); 17 | [output(:,1), output(:,2)] = full_adder(input(:,1),input(:,2),input(:,3)); 18 | truth_table = [input output]; 19 | 20 | case 'nbit_adder' 21 | % cascading adder - n-bit binary adder 22 | bit = input(1); 23 | A = input(2); 24 | B = input(3); 25 | input_A = de2bi(A,bit); 26 | input_B = de2bi(B,bit); 27 | Answer = A + B; 28 | 29 | for n = 1:bit 30 | if n ==1 31 | [S(n),Cout(n)] = full_adder(input_A(n),input_B(n),0); 32 | else 33 | [S(n),Cout(n)] = full_adder(input_A(n),input_B(n),Cout(n-1)); 34 | end 35 | end 36 | 37 | pred = bi2de([S Cout(n)],2); 38 | Correct = pred == Answer; 39 | 40 | truth_table = [S Cout(n)]; 41 | end 42 | 43 | 44 | %% functions 45 | function [S,C] = half_adder(A,B) 46 | 47 | S = xor(A,B); 48 | C = and(A,B); 49 | 50 | end 51 | 52 | function [Sout,Cout] = full_adder(A,B,C) 53 | 54 | [S_1,C_1] = half_adder(A,B); % first half adder 55 | 56 | [Sout,C_2] = half_adder(S_1,C); % second half adder 57 | 58 | Cout = or(C_1,C_2); %final carry 59 | 60 | end 61 | 62 | end -------------------------------------------------------------------------------- /Support files/other/Datasets/getImage.m: -------------------------------------------------------------------------------- 1 | function [image_resize,image_resize_gaussian] = getImage(file_dir,reduced_size, noise_type, grey) 2 | % Example: 'D:\temp\branches\working-branch\Support files\other\Datasets\101 caltech\101_ObjectCategories.tar\101_ObjectCategories\llama/*.jpg' 3 | 4 | image = imread(file_dir); 5 | image_resize = imresize(image, [reduced_size reduced_size]); 6 | if grey 7 | if size(image_resize,3) >1 8 | image_resize = rgb2gray(image_resize); 9 | end 10 | end 11 | subplot(1,2,1) 12 | imagesc(image_resize) 13 | 14 | image_resize_gaussian = imnoise(image_resize, noise_type); 15 | subplot(1,2,2) 16 | imagesc(image_resize_gaussian) 17 | 18 | image_resize = double(image_resize); 19 | image_resize_gaussian = double(image_resize_gaussian); 20 | 21 | -------------------------------------------------------------------------------- /Support files/other/Datasets/handDigits.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/handDigits.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/input_decay_example.m: -------------------------------------------------------------------------------- 1 | clear 2 | % random matrix 3 | H = zeros(10); 4 | f_pos = randi([1 size(H,1).^2],10,1); 5 | H(f_pos) = 2*rand(length(f_pos), 1)-1; 6 | 7 | % pad multipliers 8 | width = 4; 9 | [x,y] = ndgrid(-2.1:(4.2/(2*width)):2.1); 10 | D=2/4*real((4-x.^2-y.^2).^0.5); 11 | 12 | % pad location 13 | w_adj = 2*width+1; 14 | pad_H = padarray(H,[w_adj w_adj],0); 15 | 16 | s=size(pad_H); 17 | N=length(s); 18 | [c1{1:N}]=ndgrid(1:w_adj); 19 | c2(1:N)={ceil(w_adj/2)}; 20 | offsets=sub2ind(s,c1{:}) - sub2ind(s,c2{:}); 21 | 22 | B = pad_H; 23 | 24 | for i = 1:length(f_pos) 25 | 26 | pos(i) = f_pos(i) + w_adj*(size(H,1) + 2*w_adj) + 2*(ceil(f_pos(i)/size(H,1))-1)*w_adj + w_adj; 27 | 28 | B(pos(i) + offsets) = B(pos(i) + offsets) + D*B(pos(i)); 29 | end 30 | 31 | H2 = B(w_adj+1:end-w_adj,w_adj+1:end-w_adj); 32 | 33 | subplot(1,2,1) 34 | imagesc(H) 35 | subplot(1,2,2) 36 | imagesc(H2) 37 | 38 | 39 | %% exxample cycle through inputs 40 | input_matrix_2d = H; 41 | f_pos_width = randi([1 4],size(f_pos)); 42 | for i = 1:length(f_pos) 43 | t = zeros(size(H)); 44 | t(f_pos(i)) = H(f_pos(i)); 45 | [t] = adjustInputShape(t,f_pos_width(i)); 46 | input_matrix_2d = input_matrix_2d + t; 47 | end 48 | 49 | input_matrix_2d = (max(max(H))-min(min(H))).* input_matrix_2d./(max(max(input_matrix_2d))-min(min(input_matrix_2d))); 50 | 51 | subplot(1,2,1) 52 | imagesc(H) 53 | colorbar 54 | subplot(1,2,2) 55 | imagesc(input_matrix_2d) 56 | colorbar -------------------------------------------------------------------------------- /Support files/other/Datasets/iris.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Datasets/iris.mat -------------------------------------------------------------------------------- /Support files/other/Datasets/makeMaze.m: -------------------------------------------------------------------------------- 1 | function M = makeMaze(n) 2 | showProgress = false; 3 | 4 | colormap([1,1,1;1,1,1;0,0,0]); 5 | set(gcf,'color','w'); 6 | 7 | NoWALL = 0; 8 | WALL = 2; 9 | NotVISITED = -1; 10 | VISITED = -2; 11 | 12 | m = 2*n+3; 13 | M = NotVISITED(ones(m)); 14 | offsets = [-1, m, 1, -m]; 15 | 16 | M([1 2:2:end end],:) = WALL; 17 | M(:,[1 2:2:end end]) = WALL; 18 | 19 | currentCell = sub2ind(size(M),3,3); 20 | M(currentCell) = VISITED; 21 | 22 | S = currentCell; 23 | 24 | while (~isempty(S)) 25 | moves = currentCell + 2*offsets; 26 | unvistedNeigbors = find(M(moves)==NotVISITED); 27 | 28 | if (~isempty(unvistedNeigbors)) 29 | next = unvistedNeigbors(randi(length(unvistedNeigbors),1)); 30 | M(currentCell + offsets(next)) = NoWALL; 31 | 32 | newCell = currentCell + 2*offsets(next); 33 | if (any(M(newCell+2*offsets)==NotVISITED)) 34 | S = [S newCell]; 35 | end 36 | 37 | currentCell = newCell; 38 | M(currentCell) = VISITED; 39 | else 40 | currentCell = S(1); 41 | S = S(2:end); 42 | end 43 | 44 | if (showProgress) 45 | image(M-VISITED); 46 | axis equal off; 47 | drawnow; 48 | pause(.01); 49 | end 50 | end 51 | 52 | image(M-VISITED); 53 | axis equal off; -------------------------------------------------------------------------------- /Support files/other/Datasets/matlab-maze/README.md: -------------------------------------------------------------------------------- 1 | # matlab-maze 2 | This function generates a random maze and it's associated result-path. 3 | 4 | `[lines,board,hist,result] = maze(rowDim,colDim,start,stop,doPlot,printResult)` 5 | 6 | input: 7 | 8 | >optional: 9 | 10 | rowDim: default: 14 11 | colDim: default: 14 12 | start: startfield of the resultpath; default: [1,1] (down-left) 13 | stop: targetfield of the resultpath; default: [rowDim, colDim] (top-right) 14 | doPlot: plot to new figure; default: true 15 | printResult: plot the result-path; default: true 16 | > output: 17 | 18 | lines: nx2 array, containing all lines of the maze, where a line segment (for example [0,0;1,0]) 19 | is separated by a NaN-entry. This allows to plot the whole maze directly with 20 | plot(lines(:,1),lines(:,2)) 21 | board: (2*rowDim) by 2*colDim boolean-array, where walls have a truth-value 1, free space 0 22 | can be inspected easyli with spy(board) 23 | hist: the path of the maze-generation. Whenever e backtrack was performed, a NaN-value was insearted. 24 | result: the most direct path from the startpoint to the endpoint 25 | 26 | For example, generate a 20x20 maze with associated result-path from top-left to bottom-right: 27 | 28 | `maze(20,20,[1,20],[20,1])` 29 | -------------------------------------------------------------------------------- /Support files/other/Datasets/robot.m: -------------------------------------------------------------------------------- 1 | %% Assess genotype on robot task 2 | function [individual,states] = robot(individual,config) 3 | 4 | % store current seed and reset seed for simulations -- why? robot simulation 5 | % starts from random positions 6 | scurr = rng; 7 | temp_seed = scurr.Seed; 8 | rng(1,'twister'); 9 | 10 | % If watch simulation, only run one test, else run N tests 11 | if config.run_sim 12 | num_tests = config.show_robot_tests; 13 | else 14 | num_tests = config.robot_tests; 15 | end 16 | 17 | % run robot simulation 18 | if config.robot_tests <= 4 && config.run_sim == 0 19 | %temp_geno = genotype; 20 | for i = 1:num_tests 21 | [~,temp_geno(i),states]= robotSim(config.robot_behaviour,config.time_steps,'max',[],individual,config); 22 | 23 | %record fitness 24 | train_error(i) = temp_geno(i).train_error; 25 | val_error(i) = temp_geno(i).val_error; 26 | test_error(i) = temp_geno(i).test_error; 27 | end 28 | else 29 | for i = 1:num_tests 30 | [~,individual,states]= robotSim(config.robot_behaviour,config.time_steps,'max',[],individual,config); 31 | %record fitness 32 | train_error(i) = individual.train_error; 33 | val_error(i) = individual.val_error; 34 | test_error(i) = individual.test_error; 35 | end 36 | end 37 | 38 | %assign final fitness 39 | individual.train_error = mean(train_error); 40 | individual.val_error = mean(val_error); 41 | individual.test_error = mean(test_error); 42 | 43 | % Go back to old seed 44 | rng(temp_seed,'twister'); -------------------------------------------------------------------------------- /Support files/other/Datasets/rsquared.m: -------------------------------------------------------------------------------- 1 | 2 | function Rsq = rsquared(x,y) 3 | 4 | Bbar = mean(x); 5 | SStot = sum((x - Bbar).^2); 6 | SSreg = sum((y - Bbar).^2); 7 | SSres = sum((x - y).^2); 8 | R2 = 1 - SSres/SStot; 9 | R = corrcoef(x,y); 10 | Rsq = R(1,2).^2; 11 | -------------------------------------------------------------------------------- /Support files/other/Datasets/split_train_test3way.m: -------------------------------------------------------------------------------- 1 | function [train,xVal,test] = split_train_test3way(sample, trainPercentage, xvalSize, testSize) 2 | 3 | % SPLIT_TRAIN_TEST splits the "sample" time series into a train and a 4 | % test subsequence such that the train subsequence has a length of 5 | % trainPercentage of the original sample length 6 | 7 | % Created April 30, 2006, D. Popovici 8 | % Copyright: Fraunhofer IAIS 2006 / Patent pending 9 | 10 | nSamplePoints = size(sample, 1) ; 11 | nTrainPoints = floor(nSamplePoints * trainPercentage) ; 12 | 13 | 14 | if nargin < 3 15 | train = sample(1:nTrainPoints,:) ; 16 | test = sample(nTrainPoints+1:end,:) ; 17 | xVal = []; 18 | else 19 | 20 | nValPoints = floor(nSamplePoints * xvalSize) ; 21 | nTestPoints = floor(nSamplePoints * testSize) ; 22 | 23 | train = sample(1:nTrainPoints,:) ; 24 | xVal = sample(nTrainPoints+1:nTrainPoints+nValPoints,:) ; 25 | test = sample(nTrainPoints+1+nValPoints:end,:) ; 26 | 27 | end 28 | 29 | -------------------------------------------------------------------------------- /Support files/other/Datasets/truth_table.m: -------------------------------------------------------------------------------- 1 | function T = truth_table(N) 2 | % Truth Table Generator 3 | % T = truth_table(N); 4 | % 5 | % Inputs: 6 | % N: Number of bits; 7 | % 8 | % Outputs: 9 | % T: Truth Table; 10 | % 11 | % Example: 12 | % T = truth_table(2) 13 | % T = 14 | % 0 0 15 | % 0 1 16 | % 1 0 17 | % 1 1 18 | L = 2^N; 19 | T = zeros(L,N); 20 | for i=1:N 21 | temp = [zeros(L/2^i,1); ones(L/2^i,1)]; 22 | T(:,i) = repmat(temp,2^(i-1),1); 23 | end -------------------------------------------------------------------------------- /Support files/other/Metrics/infodynamics.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Metrics/infodynamics.jar -------------------------------------------------------------------------------- /Support files/other/Metrics/lyapunovExponent.m: -------------------------------------------------------------------------------- 1 | %% This function calculates the Largest Lyapunov Exponent of the provided reservoir. 2 | % The calculation is done by applying a sinewave to two identical 3 | % reservoirs with one experiencing a small perturbation. Therefore, the LE 4 | % is representative of the difference in distance between resulting 5 | % trajectories 6 | 7 | function [LE] = lyapunovExponent(individual,config,seed) 8 | 9 | %% Define two identical input sequences, but the second is perturbed at some time T 10 | rng(seed,'twister'); 11 | config.wash_out = 50; 12 | 13 | n_internal_units = individual.total_units; 14 | n_input_units = individual.n_input_units; 15 | 16 | data_length = n_internal_units*2 + config.wash_out;%400; 17 | data_sequence = 2*rand(data_length,n_input_units)-1; 18 | 19 | T = data_length/2; % perturbation time 20 | 21 | % rescale for each reservoir 22 | data_sequence_1 = data_sequence.*config.scaler; 23 | data_sequence_2 = data_sequence.*config.scaler; 24 | 25 | %perturb signal at time T 26 | pert = 10e-6; 27 | data_sequence_2(T,:) = data_sequence_2(T,:) + pert; 28 | 29 | X_unpert = config.assessFcn(individual,data_sequence_1,config); 30 | X_pert = config.assessFcn(individual,data_sequence_2,config); 31 | 32 | for i = 1:size(X_pert,1) 33 | d(i,:) = norm(X_unpert(i,:)-X_pert(i,:)); 34 | end 35 | 36 | % lambda = lim(k->inf) 1/k ln(yk/y0) 37 | LE = log(mean(nonzeros(d))/pert); % rate of divergence, with ?0 being the 38 | %initial distance between the perturbed and the unperturbed trajectory, 39 | %and ? k being the distance at time k 40 | 41 | -------------------------------------------------------------------------------- /Support files/other/Metrics/mutualInformation.m: -------------------------------------------------------------------------------- 1 | % MUTUAL_INFORMATION 2 | % A mutual information estimate from samples. 3 | % 4 | % I = mutual_information(X, Y) 5 | % I = mutual_information(X, Y, 'key', value, ...) 6 | % 7 | % where 8 | % 9 | % X and Y are signal sets. 10 | % 11 | % I is the estimated mutual information. 12 | % 13 | % Optional input arguments in 'key'-value pairs: 14 | % 15 | % XLAG and YLAG ('xLag', 'yLag') are integers which 16 | % denote the amount of lag to apply to signal X and Y, 17 | % respectively. Default 0. 18 | % 19 | % K ('k') is an integer which denotes the number of nearest 20 | % neighbors to be used by the estimator. Default 1. 21 | % 22 | % Type 'help tim' for more documentation. 23 | 24 | % Description: Mutual information estimation 25 | % Documentation: mutual_information.txt 26 | 27 | function I = mutualInformation(X, Y, varargin) 28 | 29 | % Package initialization 30 | eval(package_init(mfilename('fullpath'))); 31 | 32 | concept_check(nargin, 'inputs', 2); 33 | concept_check(nargout, 'outputs', 0 : 1); 34 | 35 | if isnumeric(X) 36 | X = {X}; 37 | end 38 | 39 | if isnumeric(Y) 40 | Y = {Y}; 41 | end 42 | 43 | % Optional input arguments. 44 | k = 1; 45 | xLag = 0; 46 | yLag = 0; 47 | %eval(process_options({'k', 'xLag', 'yLag'}, varargin)); 48 | 49 | if ~iscell(X) || ~iscell(Y) 50 | error('X or Y is not a cell-array.'); 51 | end 52 | 53 | if numel(X) ~= numel(Y) 54 | error('The number of trials in X and Y differ.'); 55 | end 56 | 57 | % Pass parameter error checking to entropy_combination. 58 | 59 | I = entropy_combination(... 60 | [X(:)'; Y(:)'], ... 61 | [1, 1, 1; 2, 2, 1], ... 62 | 'lagSet', {xLag, yLag}, ... 63 | 'k', k); -------------------------------------------------------------------------------- /Support files/other/Metrics/transferEntropy.m: -------------------------------------------------------------------------------- 1 | % TRANSFER_ENTROPY 2 | % A transfer entropy estimate from samples. 3 | % 4 | % I = transfer_entropy(X, Y, W) 5 | % I = transfer_entropy(X, Y, W, 'key', value, ...) 6 | % 7 | % where 8 | % 9 | % X, Y, and W are signal sets. 10 | % 11 | % Optional input arguments in 'key'-value pairs: 12 | % 13 | % XLAG, YLAG, and WLAG ('xLag', 'yLag', 'wLag') are integers which 14 | % denote the amount of lag to apply to signal X, Y, and Z, 15 | % respectively. Default 0. 16 | % 17 | % K ('k') is an integer which denotes the number of nearest 18 | % neighbors to be used by the estimator. Default 1. 19 | % 20 | % Type 'help tim' for more documentation. 21 | 22 | % Description: Transfer entropy estimation 23 | % Documentation: transfer_entropy.txt 24 | 25 | function I = transferEntropy(X, Y, W, varargin) 26 | 27 | % Package initialization 28 | eval(package_init(mfilename('fullpath'))); 29 | 30 | concept_check(nargin, 'inputs', 3); 31 | concept_check(nargout, 'outputs', 0 : 1); 32 | 33 | % Optional input arguments. 34 | xLag = 0; 35 | yLag = 0; 36 | wLag = 0; 37 | k = 1; 38 | eval(process_options({'k', 'xLag', 'yLag', 'wLag'}, varargin)); 39 | 40 | if isnumeric(X) 41 | X = {X}; 42 | end 43 | 44 | if isnumeric(Y) 45 | Y = {Y}; 46 | end 47 | 48 | if isnumeric(W) 49 | W = {W}; 50 | end 51 | 52 | if ~iscell(X) || ~iscell(Y) || ~iscell(W) 53 | error('X, Y, or W is not a cell-array.'); 54 | end 55 | 56 | if numel(X) ~= numel(Y) || numel(X) ~= numel(W) 57 | error('The number of trials in X, Y, and W differ.'); 58 | end 59 | 60 | % Pass parameter error checking to entropy_combination. 61 | 62 | I = entropy_combination(... 63 | [W(:)'; X(:)'; Y(:)'], ... 64 | [1, 2, 1; 2, 3, 1; 2, 2, -1], ... 65 | 'lagSet', {wLag, xLag, yLag}, ... 66 | 'k', k); -------------------------------------------------------------------------------- /Support files/other/NSGA-II/calc_crowding.m: -------------------------------------------------------------------------------- 1 | function population = calc_crowding(population, fronts) 2 | 3 | num_objectives = length( population(1).objectives ); 4 | 5 | for front = 1:length(fronts) 6 | 7 | front_individuals = fronts(front).individuals; 8 | front_population = population(front_individuals); 9 | num_individuals = length(front_individuals); 10 | objectives = vertcat(front_population.objectives); 11 | objectives = [objectives, front_individuals']; 12 | 13 | for i = 1:num_objectives 14 | 15 | objectives = sortrows(objectives, i); 16 | col_index = num_objectives+1; 17 | population( objectives(1, col_index) ).distance = Inf; % the first individual 18 | population( objectives(num_individuals, col_index) ).distance = Inf; % the last individual 19 | 20 | min_objective = objectives(1, i); 21 | max_objective = objectives(num_individuals, i); 22 | 23 | for j = 2:(num_individuals-1) 24 | id = objectives(j, col_index); 25 | population(id).distance = population(id).distance +... 26 | (objectives(j+1, i) - objectives(j-1, i)) /... 27 | (max_objective - min_objective); 28 | end 29 | 30 | end 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/calc_dommat.m: -------------------------------------------------------------------------------- 1 | function domination_matrix = calc_dommat(num_violations, violation_sum, objectives) 2 | 3 | % Calculate the domination matrix using constrained-domination. 4 | % domination_matrix(p,q)=1: p dset q 5 | % domination_matrix(p,q)=-1: q dset p 6 | % domination_matrix(p,q)=0: no domination 7 | 8 | num_individuals = size(objectives, 1); 9 | num_objectives = size(objectives, 2); 10 | domination_matrix = zeros(num_individuals, num_individuals); 11 | 12 | for p = 1:num_individuals-1 13 | 14 | for q = p+1:num_individuals 15 | 16 | % p and q are both feasible 17 | if(num_violations(p) == 0 && num_violations(q)==0) 18 | pdomq = false; 19 | qdomp = false; 20 | for i = 1:num_objectives 21 | if( objectives(p, i) < objectives(q, i) ) % minimization! 22 | pdomq = true; 23 | elseif(objectives(p, i) > objectives(q, i)) 24 | qdomp = true; 25 | end 26 | end 27 | 28 | if( pdomq && ~qdomp ) 29 | domination_matrix(p, q) = 1; 30 | elseif(~pdomq && qdomp ) 31 | domination_matrix(p, q) = -1; 32 | end 33 | 34 | % p is feasible, and q is infeasible 35 | elseif(num_violations(p) == 0 && num_violations(q)~=0) 36 | domination_matrix(p, q) = 1; 37 | 38 | % q is feasible, and p is infeasible 39 | elseif(num_violations(p) ~= 0 && num_violations(q)==0) 40 | domination_matrix(p, q) = -1; 41 | 42 | % p and q are both infeasible 43 | else 44 | if(violation_sum(p) < violation_sum(q)) 45 | domination_matrix(p, q) = 1; 46 | elseif(violation_sum(p) > violation_sum(q)) 47 | domination_matrix(p, q) = -1; 48 | end 49 | end 50 | end 51 | end 52 | 53 | domination_matrix = domination_matrix - domination_matrix'; 54 | end 55 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/calc_stats.m: -------------------------------------------------------------------------------- 1 | function state = calc_stats(state, population) 2 | 3 | rank_vector = vertcat(population.rank); 4 | rank_vector = sort(rank_vector); 5 | state.front_count = rank_vector(length(population)); 6 | state.f1_count = length( find(rank_vector==1) ); 7 | 8 | end 9 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/calc_wnorm_dist.m: -------------------------------------------------------------------------------- 1 | function distance = calc_wnorm_dist(points, ref_points, max_min, weight) 2 | 3 | % Calculate the weighted Euclidean distance from "points" to "ref_points" 4 | num_ref_points = size(ref_points, 1); 5 | num_points = size(points, 1); 6 | 7 | distance = zeros(num_points, num_ref_points); 8 | 9 | for ipt = 1:num_ref_points 10 | ref_point = ref_points(ipt, :); 11 | for i = 1:num_points 12 | wieght_norm_dist = ((points(i, :)-ref_point) ./ max_min).^2 .* weight; 13 | distance(i, ipt) = sqrt(sum(wieght_norm_dist)); 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/constraints_function.m: -------------------------------------------------------------------------------- 1 | function cons = constraints_function(y,config) 2 | cons = zeros(1, config.num_constraints); 3 | end -------------------------------------------------------------------------------- /Support files/other/NSGA-II/crossoverNSGAII.m: -------------------------------------------------------------------------------- 1 | function population = crossoverNSGAII(config, population) 2 | 3 | for individual = 1:2:length(population) 4 | 5 | parent1 = population(individual); 6 | parent2 = population(individual+1); 7 | 8 | % Create children 9 | child1 = parent1; 10 | child2 = parent2; 11 | 12 | % crossover 13 | child1.variables = config.recFcn(parent1.variables,parent2.variables,config); 14 | child2.variables = config.recFcn(parent2.variables,parent1.variables,config); 15 | 16 | %% final checks 17 | if isequal(child1, parent1) ~= 1 18 | child1.evaluated = 0; 19 | end 20 | 21 | if isequal(child2, parent2) ~= 1 22 | child2.evaluated = 0; 23 | end 24 | % 25 | population(individual) = child1; 26 | population(individual+1) = child2; 27 | 28 | end 29 | end 30 | 31 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/extract_population.m: -------------------------------------------------------------------------------- 1 | function new_population = extract_population(config, combined_population) 2 | 3 | popSize = length(combined_population) / 2; 4 | new_population = combined_population(1:popSize); 5 | rank_vector = vertcat(combined_population.rank); 6 | 7 | n = 0; % Number of individuals in the next population 8 | current_rank = 1; 9 | individuals = find(rank_vector == current_rank); 10 | num_individuals = length(individuals); % Number of individuals in the current front 11 | 12 | while( n + num_individuals <= popSize ) 13 | 14 | new_population( n+1 : n+num_individuals ) = combined_population( individuals ); 15 | n = n + num_individuals; 16 | current_rank = current_rank + 1; 17 | individuals = find(rank_vector == current_rank); 18 | num_individuals = length(individuals); 19 | 20 | end 21 | 22 | % If the number of individuals in the next front plus the number of individuals 23 | % in the current front is greater than the population size, then select the 24 | % best individuals by corwding distance. 25 | 26 | if( n < popSize ) 27 | if(~isempty(config.ref_points)) 28 | distance = vertcat(combined_population(individuals).pref_dist); 29 | distance = [distance, individuals]; 30 | distance = sortrows( distance, 1); 31 | % Select the individuals with smallest preference distance 32 | idxSelect = distance( 1:popSize-n, 2); 33 | new_population(n+1 : popSize) = combined_population(idxSelect); 34 | else 35 | distance = vertcat(combined_population(individuals).distance); 36 | distance = [distance, individuals]; 37 | % Sort the individuals in descending order of crowding 38 | % distance in the front. 39 | distance = flipud( sortrows( distance, 1) ); 40 | % Select the (popsize-n) individuals with largest crowding distance. 41 | idxSelect = distance( 1:popSize-n, 2); 42 | new_population(n+1 : popSize) = combined_population(idxSelect); 43 | end 44 | end 45 | 46 | end 47 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/fitnessNSGAII.m: -------------------------------------------------------------------------------- 1 | %% Objective function 2 | function y = fitnessNSGAII(genotype,config) 3 | 4 | %Assess each task 5 | y = zeros(1,config.num_objectives); 6 | for j = 1:config.num_objectives 7 | config.train_input_sequence = config.data{1,j}.train_input_sequence; 8 | config.train_output_sequence = config.data{1,j}.train_output_sequence; 9 | 10 | config.val_input_sequence = config.data{1,j}.val_input_sequence; 11 | config.val_output_sequence = config.data{1,j}.val_output_sequence; 12 | 13 | config.test_input_sequence = config.data{1,j}.test_input_sequence; 14 | config.test_output_sequence = config.data{1,j}.test_output_sequence; 15 | 16 | config.wash_out = config.data{1,j}.wash_out; 17 | config.err_type = config.data{1,j}.err_type; 18 | 19 | config.task_num_inputs = size(config.train_input_sequence,2); 20 | config.task_num_outputs = size(config.train_output_sequence,2); 21 | 22 | genotype = config.testFcn(genotype,config); 23 | y(j) = getError(config.error_to_check,genotype); 24 | %sum(genotype.valError);%sum(genotype.trainError + genotype.valError); 25 | end 26 | 27 | end -------------------------------------------------------------------------------- /Support files/other/NSGA-II/get_front.m: -------------------------------------------------------------------------------- 1 | function individuals = get_front(population, front) 2 | 3 | individuals = []; 4 | for i = 1:length(population) 5 | if population(i).rank == front 6 | individuals = [individuals; i]; 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/mutNSGAII.m: -------------------------------------------------------------------------------- 1 | function population = mutNSGAII(config, population) 2 | 3 | 4 | for individual = 1:length(population) 5 | 6 | % Perform mutation. 7 | parent = population(individual); 8 | child = parent; 9 | 10 | child.variables = config.mutFcn(child.variables,config); 11 | 12 | if isequal(parent, child) ~= 1 13 | child.evaluated = 0; 14 | end 15 | 16 | population(individual) = child; 17 | 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/plot_front.m: -------------------------------------------------------------------------------- 1 | function F = plot_front(population, ref_individual, fronts, objs, clear_points,generation,F,config) 2 | 3 | persistent pareto_plot; 4 | 5 | cmap = hsv(length(fronts)+1); 6 | 7 | if ishandle(pareto_plot) == 1 8 | ax = pareto_plot.CurrentAxes; 9 | else 10 | pareto_plot = figure('Name', 'Pareto Plot'); 11 | ax = gca; 12 | grid(ax, 'on'); 13 | switch(objs) 14 | case 2 15 | xlabel(ax, config.dataset_list{1}); 16 | ylabel(ax, config.dataset_list{2}); 17 | case 3 18 | xlabel(ax, config.dataset_list{1}); 19 | ylabel(ax, config.dataset_list{2}); 20 | zlabel(ax, config.dataset_list{3}); 21 | end 22 | hold(ax, 'on'); 23 | end 24 | 25 | title(strcat('Generation: ',num2str(generation))); 26 | 27 | if(clear_points) 28 | delete(ax.Children); 29 | end 30 | 31 | old_limits = [ax.XLim, ax.YLim]; 32 | 33 | % Plot the reference individual 34 | if ~isempty(ref_individual) 35 | objectives = ref_individual.objectives; 36 | switch(objs) 37 | case 2 38 | scatter(ax, objectives(:,1), objectives(:,2), 36, cmap(1,:), 'd'); 39 | case 3 40 | scatter3(ax, objectives(:,1), objectives(:,2),objectives(:,3), 36, cmap(1,:), 'd'); 41 | end 42 | end 43 | 44 | for i = 1:length(fronts) 45 | 46 | individuals = get_front(population, fronts(i)); 47 | objectives = vertcat(population(individuals).objectives); 48 | switch(objs) 49 | case 2 50 | scatter(ax, objectives(:,1), objectives(:,2), 36,cmap(i+1,:)); 51 | case 3 52 | scatter3(ax, objectives(:,1), objectives(:,2), objectives(:,3), 36,cmap(i+1,:)); 53 | end 54 | % new_limits = [[0 max(objectives(:,obj1_idx))],[0 max(max(objectives(:,obj2_idx)))]];%[ax.XLim, ax.YLim]; 55 | % 56 | % if old_limits(1) < new_limits(1) 57 | % new_limits(1) = old_limits(1); 58 | % end 59 | % if old_limits(2) < new_limits(2) 60 | % new_limits(2) = old_limits(2); 61 | % end 62 | % if old_limits(3) < new_limits(3) 63 | % new_limits(3) = old_limits(3); 64 | % end 65 | % if old_limits(4) < new_limits(4) 66 | % new_limits(4) = old_limits(4); 67 | % end 68 | % 69 | % old_limits = new_limits; 70 | end 71 | 72 | 73 | %axis(ax, new_limits); 74 | drawnow; 75 | 76 | %drawnow 77 | F(generation) = getframe(pareto_plot); 78 | end 79 | -------------------------------------------------------------------------------- /Support files/other/NSGA-II/selectionNSGAII.m: -------------------------------------------------------------------------------- 1 | function new_population = selectionNSGAII(config, population) 2 | 3 | num_individuals = length(population); 4 | selected_individuals = zeros(1, num_individuals); 5 | randnum = randi(num_individuals, [1, 2 * num_individuals]); 6 | 7 | j = 1; 8 | for i = 1:2:(2*num_individuals) 9 | 10 | p1 = randnum(i); 11 | p2 = randnum(i+1); 12 | 13 | if(~isempty(config.ref_points)) 14 | if( (population(p1).rank < population(p2).rank) || ... 15 | ((population(p1).rank == population(p2).rank) &&... 16 | (population(p1).pref_dist < population(p2).pref_dist))) 17 | selected_individuals(j) = p1; 18 | else 19 | selected_individuals(j) = p2; 20 | end 21 | else 22 | if((population(p1).rank < population(p2).rank) ||... 23 | ((population(p1).rank == population(p2).rank) &&... 24 | (population(p1).distance > population(p2).distance) )) 25 | selected_individuals(j) = p1; 26 | else 27 | selected_individuals(j) = p2; 28 | end 29 | end 30 | j = j + 1; 31 | end 32 | 33 | new_population = population(selected_individuals); 34 | 35 | end 36 | -------------------------------------------------------------------------------- /Support files/other/Plots/adjancencyMatrixPlot.m: -------------------------------------------------------------------------------- 1 | 2 | %% This is rough playaround - not sure it shows much at the moment... 3 | % Adjacency plot and strength need adjusting. 4 | 5 | figure1 = figure; 6 | 7 | for n = 8:9 8 | 9 | D = database_esnMajor(n).connectWeights{1,1}; 10 | G = graph(D,'upper'); 11 | 12 | % adjacency on graph 13 | B = adjacency(G); 14 | nn = numnodes(G); 15 | [s,t] = findedge(G); 16 | A = sparse(s,t,G.Edges.Weight,nn,nn); 17 | A = A + A.' - diag(diag(A)); 18 | 19 | 20 | % complete guess, just playing around... 21 | D = D +zeros(100,100); 22 | N=zeros(100,100); 23 | for i = 1:100 24 | for j = 1:100 25 | [~,N(i,:)] = knnsearch(D(i,j),D(i,:)','K',10); 26 | aN(i) = mean(N(i,:)); 27 | end 28 | end 29 | 30 | set(0,'currentFigure',figure1) 31 | % plot adjacency matrix 32 | subplot(1,3,1) 33 | imagesc(A) 34 | title('Adjacency') 35 | colormap(gca,bluewhitered) 36 | 37 | %plot original weights 38 | subplot(1,3,2) 39 | imagesc(D) 40 | title('Original') 41 | colormap(gca,bluewhitered) 42 | 43 | %plot strength of connectivity?? 44 | subplot(1,3,3) 45 | imagesc(A.*(aN'*aN)) 46 | title('Strength') 47 | colormap(gca,bluewhitered) 48 | pause(2) 49 | end 50 | 51 | 52 | -------------------------------------------------------------------------------- /Support files/other/Plots/behaviourGUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/behaviourGUI.fig -------------------------------------------------------------------------------- /Support files/other/Plots/calculateNumEdges.m: -------------------------------------------------------------------------------- 1 | figure 2 | 3 | nsize = [25,50,100,200,400]; 4 | latt_size = [5,7,10,14,20]; 5 | for i = 1:length(nsize) 6 | 7 | ring_u(i) = nsize(i); 8 | ring_d(i) = nsize(i) + nsize(i); 9 | 10 | % corners 11 | perm = (latt_size(i)-1)*3; 12 | latt_u(i) = 2*latt_size(i)^2 - 2*latt_size(i) + 2*(latt_size(i)-1)^2 + latt_size(i)^2; 13 | latt_d(i) = latt_u(i)*2 - latt_size(i)^2; 14 | 15 | esn_d(i) = nsize(i)^2; 16 | end 17 | 18 | mBar = [ring_u;ring_d;latt_u;latt_d;esn_d]'; 19 | bar(mBar,'FaceColor','flat'); 20 | xticklabels({'25','50','100','200','400'}) 21 | legend('ring(u)','ring(d)','lattice(u)','lattice(d)','esn(d)','Location','northwest') 22 | xlabel('size') 23 | ylabel('no. of weights') 24 | set(gca,'FontSize',12,'FontName','Arial') 25 | set(gcf,'renderer','OpenGL') -------------------------------------------------------------------------------- /Support files/other/Plots/filmDatabase.m: -------------------------------------------------------------------------------- 1 | config.discrete = 0; % select '1' for binary input for discrete systems 2 | config.nbits = 16; % only applied if config.discrete = 1; if wanting to convert data for binary/discrete systems 3 | config.preprocess = 1; % basic preprocessing, e.g. scaling and mean variance 4 | config.dataset = 'test_plot'; % Task to evolve for 5 | 6 | % get any additional params. This might include: 7 | % details on reservoir structure, extra task variables, etc. 8 | config = getAdditionalParameters(config); 9 | 10 | % get dataset information 11 | config = selectDataset(config); 12 | config.figure_array(2) = figure; 13 | v = VideoWriter('Ising_10x10','MPEG-4'); 14 | open(v); 15 | 16 | if exist('database') ~= 1 17 | database = population; 18 | end 19 | 20 | config.run_sim = 1; 21 | config.film = 1; 22 | step = 1; 23 | F = []; 24 | for i = 1:step:length(database)-step 25 | t_F = plotReservoirDetails(database,i,1,1,config); 26 | F = [F t_F]; 27 | end 28 | 29 | writeVideo(v,F); 30 | close(v) 31 | -------------------------------------------------------------------------------- /Support files/other/Plots/filmNS.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | f1 = figure 4 | v = VideoWriter('NS.avi'); 5 | database = all_databases{1,10}; 6 | open(v); 7 | cnt = 1; 8 | step = 25; 9 | maxMC = max(database(:,3))+5; 10 | set(f1,'position',[0,492,1657,456]) 11 | 12 | for i = 1:step:length(database)-step 13 | hold on 14 | subplot(1,3,1) 15 | scatter(database(i:i+step-1,1),database(i:i+step-1,2),20,i:i+step-1,'filled') 16 | colorbar 17 | xlabel('Kernel Rank') 18 | ylabel('Generalisation Rank') 19 | xlim([0 config.maxMinorUnits]) 20 | ylim([0 config.maxMinorUnits]) 21 | 22 | hold on 23 | subplot(1,3,2) 24 | title(strcat('Generation: ',num2str(i))) 25 | scatter(database(i:i+step-1,1),database(i:i+step-1,3),20,i:i+step-1,'filled') 26 | colorbar 27 | xlabel('Kernel Rank') 28 | ylabel('Memory Capacity') 29 | xlim([0 config.maxMinorUnits]) 30 | ylim([0 maxMC]) 31 | 32 | hold on 33 | subplot(1,3,3) 34 | scatter(database(i:i+step-1,2),database(i:i+step-1,3),20,i:i+step-1,'filled') 35 | colorbar 36 | xlabel('Generalisation Rank') 37 | ylabel('Memory Capacity') 38 | xlim([0 config.maxMinorUnits]) 39 | ylim([0 maxMC]) 40 | 41 | drawnow 42 | %pause(0.001) 43 | colormap('copper') 44 | F(cnt) = getframe(f1); 45 | writeVideo(v,F(cnt)); 46 | cnt = cnt+1; 47 | end 48 | hold off 49 | close(v) -------------------------------------------------------------------------------- /Support files/other/Plots/getAdjacenyMatrix.m: -------------------------------------------------------------------------------- 1 | function W = getAdjacenyMatrix(individual,res_indx,config) 2 | 3 | W = sparse(individual.nodes(res_indx),individual.nodes(res_indx)); 4 | source_nodes = repmat(1:individual.nodes(res_indx),config.k,1); 5 | source_nodes = source_nodes(:); 6 | 7 | G_in = [individual.RBN_node{res_indx}.input]; 8 | 9 | for i = 1:length(source_nodes) 10 | W(source_nodes(i),G_in(i)) = 1; 11 | end 12 | 13 | -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/Readme.md: -------------------------------------------------------------------------------- 1 | # Parfor progress monitor 2 | 3 | 4 | ## A Java-based `Matlab` class for progress monitoring during a `parfor` loop 5 | 6 | ### Usage 7 | Begin by creating a parallel pool. 8 | 9 | Then construct a ParforProgMon object: 10 | 11 | ppm = ParforProgMon(strWindowTitle, nNumIterations <, nProgressStepSize, nWidth, nHeight>); 12 | 13 | `strWindowTitle` is a string containing the title of the progress bar 14 | window. `nNumIterations` is an integer with the total number of 15 | iterations in the loop. 16 | 17 | #### Optional arguments 18 | `nProgressStepSize` specifies to update the progress bar every time this 19 | number of steps passes. `nWidth` and `nHeight` specify the size of the 20 | progress window. 21 | 22 | Within the `parfor` loop: 23 | 24 | parfor (nIndex = 1:nNumIterations) 25 | ppm.increment(); 26 | end 27 | 28 | ### Credits 29 | [Parfor Progress monitor](https://www.mathworks.com/matlabcentral/fileexchange/24594-parfor-progress-monitor) 30 | 31 | [Parfor Progress monitor v2](https://www.mathworks.com/matlabcentral/fileexchange/31673-parfor-progress-monitor-v2) 32 | -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$1.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgServer$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgServer$1.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgServer.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgThing.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgThing.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgWorker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor$ProgWorker.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/java/ParforProgressMonitor.class -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Dylan Muir 2 | Copyright (c) 2011, Willem-Jan de Goeij 3 | Copyright (c) 2009, The MathWorks, Inc. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the distribution 15 | * Neither the name of the The MathWorks, Inc. nor the names 16 | of its contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Support files/other/Plots/parfor progress bar/progress_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/other/Plots/parfor progress bar/progress_bar.png -------------------------------------------------------------------------------- /Support files/other/Plots/plotActivity.m: -------------------------------------------------------------------------------- 1 | function plotActivity(figureHandle,task,esnMinor,esnMajor,config, video) 2 | 3 | [trainInputSequence,trainOutputSequence,valInputSequence,valOutputSequence,... 4 | testInputSequence,testOutputSequence,nForgetPoints,errType] = selectDataset_Rodan(task); 5 | 6 | 7 | [test_error,testStates,testWeights] = assessESNonTask(esnMinor,esnMajor,... 8 | trainInputSequence,trainOutputSequence,valInputSequence,valOutputSequence,testInputSequence,testOutputSequence,... 9 | nForgetPoints,config.leakOn,errType,config.resType); 10 | 11 | %toPlot = testStates(:,1:50)'*testWeights(1,1:50); 12 | weights = (esnMinor.inputScaling.*esnMajor.connectWeights{1,1}); 13 | predict_out = testStates*testWeights'; 14 | 15 | set(0,'currentFigure',figureHandle) 16 | for i = 1:500%size(testStates,1) 17 | 18 | subplot(2,2,1) 19 | toPlot = diag(testStates(i,1:50))*weights; 20 | 21 | G = graph(toPlot,'upper'); 22 | B = adjacency(G); 23 | nn = numnodes(G); 24 | [s,t] = findedge(G); 25 | A = sparse(s,t,G.Edges.Weight,nn,nn); 26 | A = A + A.' - diag(diag(A)); 27 | 28 | imagesc(A) 29 | %imagesc(testStates(i,1:50)'*testWeights(1,1:50)) 30 | colormap(bluewhitered) 31 | 32 | subplot(2,2,2) 33 | h = plot(1+i:500+i,testStates(1+i:i+500,1:50)); 34 | xlim([1+i i+500]) 35 | F(i) = getframe(gcf); 36 | 37 | subplot(2,2,3) 38 | imagesc(testStates(i,1:50)'*testWeights(1,1:50)) 39 | 40 | subplot(2,2,4) 41 | plot(1+i:500+i,[predict_out(1+i:500+i) testOutputSequence(nForgetPoints+1+i:nForgetPoints+500+i)]) 42 | xlim([1+i i+500]) 43 | ylim([min([min(predict_out) min(testOutputSequence)])... 44 | max([max(predict_out) max(testOutputSequence)])]) 45 | 46 | F(i) = getframe(gcf); 47 | drawnow 48 | 49 | end 50 | 51 | if nargin > 5 52 | createVid(F) 53 | end 54 | 55 | end 56 | 57 | function createVid(F) 58 | 59 | % create the video writer with 1 fps 60 | writerObj = VideoWriter('activity_video.avi'); 61 | writerObj.FrameRate = 50; 62 | % set the seconds per image 63 | 64 | % open the video writer 65 | open(writerObj); 66 | % write the frames to the video 67 | writeVideo(writerObj, F); 68 | 69 | % close the writer object 70 | close(writerObj); 71 | 72 | end -------------------------------------------------------------------------------- /Support files/other/Plots/plotAndCalcSR.m: -------------------------------------------------------------------------------- 1 | 2 | function database_esnMinor = plotAndCalcSR(figureHandle,database_esnMinor,database_esnMajor,search_archive) 3 | 4 | %% calculate spectral radius 5 | opts.disp = 0; 6 | for i = 1:length(database_esnMinor) 7 | database_esnMinor(i).actualSR = max(abs(eigs(database_esnMajor(i).connectWeights{1,1},1, 'lm', opts))); 8 | end 9 | 10 | parameter = [database_esnMinor.actualSR].*[database_esnMinor.spectralRadius]; 11 | 12 | figure(figureHandle) 13 | subplot(1,3,1) 14 | scatter(search_archive(:,1),search_archive(:,2),20,parameter,'filled') 15 | map = cubehelix(length(search_archive)); 16 | colormap(map) 17 | xlabel('KR') 18 | ylabel('GR') 19 | colorbar 20 | 21 | subplot(1,3,2) 22 | scatter(search_archive(:,1),search_archive(:,3),20,parameter,'filled') 23 | map = cubehelix(length(search_archive)); 24 | colormap(map) 25 | xlabel('KR') 26 | ylabel('MC') 27 | colorbar 28 | 29 | subplot(1,3,3) 30 | scatter(search_archive(:,2),search_archive(:,3),20,parameter,'filled') 31 | map = cubehelix(length(search_archive)); 32 | colormap(map) 33 | xlabel('GR') 34 | ylabel('MC') 35 | colorbar 36 | 37 | set(gca,'FontSize',14,'FontName','Arial') 38 | set(gcf,'renderer','OpenGL') 39 | 40 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotBSVoxelfrequency.m: -------------------------------------------------------------------------------- 1 | %% plots the number of reservoirs occupying a single voxel 2 | % *use measureSpace function beforehand 3 | function plotBSVoxelfrequency(size,space_cnt) 4 | 5 | % figure 6 | [X,Y,Z] = meshgrid(1:size+1); 7 | d = space_cnt(:)> 1; 8 | [~,d]=sort(space_cnt(:),'ascend'); 9 | 10 | X = X(:); Y=Y(:); Z=Z(:); 11 | % scatter3(X(d),Y(d),Z(d),15,space_cnt(d),'filled'); 12 | % colormap(bluewhitered) 13 | 14 | figure 15 | subplot(1,3,1) 16 | scatter(X(d),Y(d),15,space_cnt(d),'filled') 17 | xlabel('KR') 18 | ylabel('GR') 19 | 20 | subplot(1,3,2) 21 | scatter(X(d),Z(d),15,space_cnt(d),'filled') 22 | xlabel('KR') 23 | ylabel('MC') 24 | 25 | subplot(1,3,3) 26 | scatter(Y(d),Z(d),15,space_cnt(d),'filled') 27 | xlabel('GR') 28 | ylabel('MC') 29 | colorbar 30 | 31 | colormap(bluewhitered) -------------------------------------------------------------------------------- /Support files/other/Plots/plotBZ.m: -------------------------------------------------------------------------------- 1 | function plotBZ(figure1,population,best_indv,loser,config) 2 | set(0,'currentFigure',figure1) 3 | 4 | set(0,'currentFigure',figure1) 5 | subplot(2,3,1) 6 | imagesc(reshape(population(best_indv).input_weights{1,1}(:,1),config.num_nodes,config.num_nodes)) 7 | title('Input Location (Best)') 8 | 9 | subplot(2,3,2) 10 | imagesc(reshape(population(best_indv).input_weights{1,2}(:,1),config.num_nodes,config.num_nodes)) 11 | title('Input Location (Best)') 12 | 13 | subplot(2,3,3) 14 | imagesc(reshape(population(best_indv).input_weights{1,3}(:,1),config.num_nodes,config.num_nodes)) 15 | title('Input Location (Best)') 16 | 17 | subplot(2,3,4) 18 | imagesc(reshape(population(loser).input_weights{1,1}(:,1),config.num_nodes,config.num_nodes)) 19 | title('Input Location (loser)') 20 | 21 | subplot(2,3,5) 22 | imagesc(reshape(population(loser).input_weights{1,2}(:,1),config.num_nodes,config.num_nodes)) 23 | title('Input Location (loser)') 24 | 25 | subplot(2,3,6) 26 | imagesc(reshape(population(loser).input_weights{1,3}(:,1),config.num_nodes,config.num_nodes)) 27 | title('Input Location (loser)') 28 | 29 | 30 | drawnow 31 | end -------------------------------------------------------------------------------- /Support files/other/Plots/plotBZinputlayer.m: -------------------------------------------------------------------------------- 1 | 2 | cnt=1; 3 | for i = 1:individual.time_period:1000 4 | subplot(1,3,1) 5 | imagesc(reshape(input_mul{1}(i,:),50,50)) 6 | title('A') 7 | subplot(1,3,2) 8 | imagesc(reshape(input_mul{2}(i,:),50,50)) 9 | title('B') 10 | subplot(1,3,3) 11 | imagesc(reshape(input_mul{3}(i,:),50,50)) 12 | title('C') 13 | drawnow 14 | F(cnt) = getframe(gcf); 15 | cnt = cnt + 1; 16 | end 17 | 18 | v = VideoWriter('BZ_laser_input','MPEG-4'); 19 | open(v); 20 | writeVideo(v,F); 21 | close(v); -------------------------------------------------------------------------------- /Support files/other/Plots/plotCA.m: -------------------------------------------------------------------------------- 1 | function plotCA(config,states) 2 | 3 | figure 4 | 5 | for i = 1:size(states,1)-1 6 | imagesc(reshape(states(i,2:end),sqrt(config.maxMinorUnits),sqrt(config.maxMinorUnits))); 7 | title(strcat('Iteration: ',num2str(i))) 8 | pause(0.05) 9 | 10 | end 11 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotCASearch.m: -------------------------------------------------------------------------------- 1 | %% plot all behaviours in behaviour space 2 | function plotCASearch(database, gen,config) 3 | 4 | all_behaviours = reshape([database.behaviours],length(config.metrics),length(database))'; 5 | 6 | set(0,'currentFigure',config.figure_array(1)) 7 | title(strcat('Gen:',num2str(gen))) 8 | v = 1:length(config.metrics); 9 | C = nchoosek(v,2); 10 | 11 | if size(C,1) > 3 12 | num_plot_x = size(C,1)/2; 13 | num_plot_y = 2; 14 | else 15 | num_plot_x = 3; 16 | num_plot_y = 1; 17 | end 18 | 19 | for i = 1:size(C,1) 20 | subplot(num_plot_x,num_plot_y,i) 21 | 22 | for p = 1:length(all_behaviours) 23 | [class(p),symmetry(p)] = getECAclass(bi2de(database(p).rules{1,1}(:,1)')); 24 | end 25 | scatter(all_behaviours(:,C(i,1)),all_behaviours(:,C(i,2)),20,1:length(all_behaviours),'filled') 26 | 27 | xlabel(config.metrics(C(i,1))) 28 | ylabel(config.metrics(C(i,2))) 29 | colormap('copper') 30 | end 31 | 32 | drawnow 33 | 34 | % classes and symmetry 35 | figure 36 | for c = 1:4 37 | subplot(2,2,c) 38 | scatter(all_behaviours(class == c,1),all_behaviours(class == c,3),20,symmetry(class == c),'filled') 39 | xlim([0 max(all_behaviours(:,1))]) 40 | ylim([0 max(all_behaviours(:,3))]) 41 | caxis([0 max(symmetry)]) 42 | title(strcat('class','',num2str(c))) 43 | xlabel('KR') 44 | ylabel('MC') 45 | %colorbar 46 | end 47 | 48 | % classes and delay 49 | figure 50 | time_period = [database.time_period]; 51 | for c = 1:4 52 | subplot(2,2,c) 53 | scatter(all_behaviours(class == c,1),all_behaviours(class == c,3),20,time_period(class == c),'filled') 54 | xlim([0 max(all_behaviours(:,1))]) 55 | ylim([0 max(all_behaviours(:,3))]) 56 | caxis([0 max(time_period)]) 57 | title(strcat('class','',num2str(c))) 58 | xlabel('KR') 59 | ylabel('MC') 60 | %colorbar 61 | end 62 | 63 | 64 | end -------------------------------------------------------------------------------- /Support files/other/Plots/plotDatabases.m: -------------------------------------------------------------------------------- 1 | function plotDatabases(figureHandle1,database1,database2,database1_name,database2_name,randPlot) 2 | 3 | if nargin <= 5 4 | % take into account first 200 in population for random search 5 | for i = 1:size(database1,1) 6 | database1(i,2:end) = database1(i,1:end-1); 7 | database1(i,1) = database2(i,1); 8 | end 9 | end 10 | 11 | set(0,'currentFigure',figureHandle1) 12 | 13 | x = 0:10; 14 | hold on 15 | 16 | % take into account first 200 in population for random search 17 | % if randPlot 18 | % for i = 1:size(database1,1) 19 | % database1(i,2:end) = database1(i,1:end-1); 20 | % database1(i,1) = database2(i,1); 21 | % end 22 | % end 23 | 24 | y = mean(database1); 25 | L = y - min(database1); 26 | U = max(database1) - y; 27 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)],'lineStyle','-','color',[1 0 0]) 28 | text(x(end)+0.15,y(end),database1_name) 29 | 30 | y = mean(database2); 31 | L = y - min(database2); 32 | U = max(database2) - y; 33 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)],'lineStyle','--','color',[0 0 0]) 34 | text(x(end)+0.15,y(end),database2_name) 35 | 36 | hold off 37 | grid on 38 | box on 39 | 40 | lb = 0:200:2000; 41 | xticklabels(lb) 42 | xlabel('Generations') 43 | ylabel('Total Coverage (\theta)') 44 | lg = legend(database1_name,database2_name,'Location','northwest'); 45 | 46 | set(gca,'FontSize',12,'FontName','Arial') 47 | set(lg,'FontSize',12) 48 | 49 | set(gcf,'renderer','OpenGL') 50 | drawnow 51 | 52 | 53 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotGridNeuron.m: -------------------------------------------------------------------------------- 1 | function plotGridNeuron(figure1,individual,best_indv,loser,config) 2 | 3 | set(0,'currentFigure',figure1) 4 | 5 | for graph_i= 1:size(config.G,2) 6 | 7 | subplot(2,size(config.G,2),graph_i) 8 | 9 | if iscell(config.G) 10 | G = config.G{graph_i}; 11 | else 12 | G = config.G; 13 | end 14 | %graph_indx = logical(full(adjacency(G))); 15 | %individual(best_indv).W{graph_i,graph_i}(~graph_indx) = 0; 16 | %individual(loser).W{graph_i,graph_i}(~graph_indx) = 0; 17 | 18 | %create graphs to plot 19 | best_G = digraph(individual(best_indv).W{graph_i,graph_i}); 20 | loser_G = digraph(individual(loser).W{graph_i,graph_i}); 21 | 22 | if config.plot_3d 23 | p = plot(best_G,'NodeLabel',{},'Layout','force3'); 24 | else 25 | p = plot(best_G,'NodeLabel',{},'Layout','force'); 26 | end 27 | p.NodeColor = 'black'; 28 | p.MarkerSize = 1; 29 | p.EdgeCData = best_G.Edges.Weight; 30 | colormap(gca,bluewhitered) 31 | xlabel('Best weights') 32 | drawnow 33 | 34 | %% plot loser 35 | subplot(2,size(config.G,2),size(config.G,2) + graph_i) 36 | if config.plot_3d 37 | p = plot(loser_G,'NodeLabel',{},'Layout','force3'); 38 | else 39 | p = plot(loser_G,'NodeLabel',{},'Layout','force'); 40 | end 41 | p.EdgeCData = loser_G.Edges.Weight; 42 | p.NodeColor = 'black'; 43 | p.MarkerSize = 1; 44 | colormap(gca,bluewhitered) 45 | xlabel('Loser weights') 46 | 47 | %pause(0.01) 48 | drawnow 49 | end 50 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotInputConnectivity.m: -------------------------------------------------------------------------------- 1 | 2 | function plotInputConnectivity(figureHandle,database_esnMinor,search_archive) 3 | 4 | %% W connectivity 5 | totalInputWeights = database_esnMinor(1).nInternalUnits*2; 6 | for i = 1:length(database_esnMinor) 7 | database_esnMinor(i).input_connectivity_actual = length(nonzeros(database_esnMinor(i).inputWeights))/totalInputWeights; 8 | end 9 | 10 | figure(figureHandle) 11 | subplot(1,3,1) 12 | scatter(search_archive(:,1),search_archive(:,2),20,[database_esnMinor.input_connectivity_actual],'filled') 13 | map = cubehelix(length(search_archive)); 14 | colormap(map) 15 | xlabel('KR') 16 | ylabel('GR') 17 | colorbar 18 | 19 | subplot(1,3,2) 20 | scatter(search_archive(:,1),search_archive(:,3),20,[database_esnMinor.input_connectivity_actual],'filled') 21 | map = cubehelix(length(search_archive)); 22 | colormap(map) 23 | xlabel('KR') 24 | ylabel('MC') 25 | colorbar 26 | 27 | subplot(1,3,3) 28 | scatter(search_archive(:,2),search_archive(:,3),20,[database_esnMinor.input_connectivity_actual],'filled') 29 | map = cubehelix(length(search_archive)); 30 | colormap(map) 31 | xlabel('GR') 32 | ylabel('MC') 33 | colorbar 34 | 35 | set(gca,'FontSize',14,'FontName','Arial') 36 | set(gcf,'renderer','OpenGL') 37 | 38 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotInternalConnectivity.m: -------------------------------------------------------------------------------- 1 | 2 | function plotInternalConnectivity(figureHandle,database_esnMinor,database_esnMajor,search_archive) 3 | 4 | %% W connectivity 5 | totalWeights = database_esnMinor(1).nInternalUnits.^2; 6 | for i = 1:length(database_esnMinor) 7 | database_esnMinor(i).connectivity_actual = length(nonzeros(database_esnMajor(i).connectWeights{1,1}))/totalWeights; 8 | end 9 | 10 | figure(figureHandle) 11 | subplot(1,3,1) 12 | scatter(search_archive(:,1),search_archive(:,2),20,[database_esnMinor.connectivity_actual],'filled') 13 | map = cubehelix(length(search_archive)); 14 | colormap(map) 15 | xlabel('KR') 16 | ylabel('GR') 17 | colorbar 18 | 19 | subplot(1,3,2) 20 | scatter(search_archive(:,1),search_archive(:,3),20,[database_esnMinor.connectivity_actual],'filled') 21 | map = cubehelix(length(search_archive)); 22 | colormap(map) 23 | xlabel('KR') 24 | ylabel('MC') 25 | colorbar 26 | 27 | subplot(1,3,3) 28 | scatter(search_archive(:,2),search_archive(:,3),20,[database_esnMinor.connectivity_actual],'filled') 29 | map = cubehelix(length(search_archive)); 30 | colormap(map) 31 | xlabel('GR') 32 | ylabel('MC') 33 | colorbar 34 | 35 | set(gca,'FontSize',14,'FontName','Arial') 36 | set(gcf,'renderer','OpenGL') 37 | 38 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotParameter.asv: -------------------------------------------------------------------------------- 1 | 2 | function plotParameter(figureHandle,search_archive,parameter,pSize) 3 | 4 | set(0,'currentFigure',figureHandle); 5 | set(gcf,'Position',[-4 340 1923 489]); 6 | 7 | if size(search_archive,2) < 3 8 | 9 | 10 | e 11 | maxGR = max(search_archive(:,2)); 12 | maxKR = max(search_archive(:,1)); 13 | maxMC = max(search_archive(:,3)); 14 | 15 | %pSize= 5; 16 | 17 | subplot(1,3,1) 18 | scatter(search_archive(:,1),search_archive(:,2),pSize,[parameter],'filled') 19 | xlim([0 maxKR]) 20 | ylim([0 maxGR]) 21 | map = cubehelix(length(search_archive)); 22 | colormap(map) 23 | xlabel('KR') 24 | ylabel('GR') 25 | colorbar 26 | set(gca,'FontSize',12,'FontName','Arial') 27 | 28 | subplot(1,3,2) 29 | scatter(search_archive(:,1),search_archive(:,3),pSize,[parameter],'filled') 30 | xlim([0 maxKR]) 31 | ylim([0 maxMC]) 32 | map = cubehelix(length(search_archive)); 33 | colormap(map) 34 | xlabel('KR') 35 | ylabel('MC') 36 | colorbar 37 | set(gca,'FontSize',12,'FontName','Arial') 38 | 39 | subplot(1,3,3) 40 | scatter(search_archive(:,2),search_archive(:,3),pSize,[parameter],'filled') 41 | xlim([0 maxGR]) 42 | ylim([0 maxMC]) 43 | map = cubehelix(length(search_archive)); 44 | colormap(map) 45 | xlabel('GR') 46 | ylabel('MC') 47 | colorbar 48 | set(gca,'FontSize',12,'FontName','Arial') 49 | 50 | set(gcf,'renderer','OpenGL') 51 | set(gcf,'PaperOrientation','landscape'); 52 | 53 | drawnow 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotParameter.m: -------------------------------------------------------------------------------- 1 | 2 | function plotParameter(figureHandle,search_archive,parameter,pSize,p1,p2) 3 | 4 | set(0,'currentFigure',figureHandle); 5 | %set(gcf,'Position',[-4 340 1923 489]); 6 | 7 | if size(search_archive,2) < 3 8 | 9 | maxGR = max(search_archive(:,2)); 10 | maxKR = max(search_archive(:,1)); 11 | 12 | scatter(search_archive(:,1),search_archive(:,2),pSize,[parameter],'filled') 13 | xlim([0 maxKR]) 14 | ylim([0 maxGR]) 15 | map = cubehelix(length(search_archive)); 16 | colormap(map) 17 | xlabel(p1) 18 | ylabel(p2) 19 | colorbar 20 | set(gca,'FontSize',12,'FontName','Arial') 21 | 22 | figure 23 | scatterhist(search_archive(:,1),search_archive(:,2)) 24 | xlim([0 maxKR]) 25 | ylim([0 maxGR]) 26 | xlabel(p1) 27 | ylabel(p2) 28 | set(gca,'FontSize',12,'FontName','Arial') 29 | 30 | else 31 | 32 | maxGR = max(search_archive(:,2)); 33 | maxKR = max(search_archive(:,1)); 34 | maxMC = max(search_archive(:,3)); 35 | 36 | %pSize= 5; 37 | 38 | subplot(1,3,1) 39 | scatter(search_archive(:,1),search_archive(:,2),pSize,[parameter],'filled') 40 | xlim([0 maxKR]) 41 | ylim([0 maxGR]) 42 | map = cubehelix(length(search_archive)); 43 | colormap(map) 44 | xlabel('KR') 45 | ylabel('GR') 46 | colorbar 47 | set(gca,'FontSize',12,'FontName','Arial') 48 | 49 | subplot(1,3,2) 50 | scatter(search_archive(:,1),search_archive(:,3),pSize,[parameter],'filled') 51 | xlim([0 maxKR]) 52 | ylim([0 maxMC]) 53 | map = cubehelix(length(search_archive)); 54 | colormap(map) 55 | xlabel('KR') 56 | ylabel('MC') 57 | colorbar 58 | set(gca,'FontSize',12,'FontName','Arial') 59 | 60 | subplot(1,3,3) 61 | scatter(search_archive(:,2),search_archive(:,3),pSize,[parameter],'filled') 62 | xlim([0 maxGR]) 63 | ylim([0 maxMC]) 64 | map = cubehelix(length(search_archive)); 65 | colormap(map) 66 | xlabel('GR') 67 | ylabel('MC') 68 | colorbar 69 | set(gca,'FontSize',12,'FontName','Arial') 70 | 71 | set(gcf,'renderer','OpenGL') 72 | set(gcf,'PaperOrientation','landscape'); 73 | 74 | drawnow 75 | 76 | end 77 | 78 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotQuality.m: -------------------------------------------------------------------------------- 1 | function plotQuality(figureHandle,database,tag,c) 2 | 3 | set(0,'currentFigure',figureHandle) 4 | 5 | x = 0:10; 6 | hold on 7 | 8 | for i = 1:length(database) 9 | y = mean(database{i}); 10 | L = y - min(database{i}); 11 | U = max(database{i}) - y; 12 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)])%,'lineStyle',tag{i},'color',c{i}) 13 | end 14 | 15 | hold off 16 | grid on 17 | box on 18 | 19 | lb = 0:200:2000; 20 | xticklabels(lb) 21 | xlabel('Generations') 22 | ylabel('Total Coverage (\theta)') 23 | %lg = legend(lg_label,'Location','northwest'); 24 | 25 | set(gca,'FontSize',12,'FontName','Arial') 26 | %set(lg,'FontSize',12) 27 | 28 | set(gcf,'renderer','OpenGL') 29 | drawnow 30 | 31 | 32 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotQualityRatio.m: -------------------------------------------------------------------------------- 1 | function plotQualityRatio(figureHandle,database,resize,type,directed) 2 | 3 | set(0,'currentFigure',figureHandle) 4 | 5 | x = 0:10; 6 | 7 | hold on 8 | for i = 1:length(database) 9 | 10 | data = database{i}/resize(i).^3; 11 | y = mean(data); 12 | L = y - min(data); 13 | U = max(data) - y; 14 | if i == 3 15 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)],'lineStyle','-','color','k') 16 | else 17 | if directed 18 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)],'lineStyle','-','color','b') 19 | else 20 | errorbar(x,[0 y(1:end)],[0 L(1:end)],[0 U(1:end)],'lineStyle','--','color','r') 21 | end 22 | end 23 | %text(mean(x),mean(y)+mean(y)*0.25,strcat(num2str(resize(i)),' node ',type{i})) 24 | 25 | end 26 | hold off 27 | 28 | lb = 0:200:2000; 29 | xticklabels(lb) 30 | xlabel('Generations') 31 | ylabel('log(r)') 32 | %lg = legend(database1_name,database2_name,'Location','northwest'); 33 | set(gca, 'YScale', 'log') 34 | set(gca,'FontSize',12,'FontName','Arial') 35 | 36 | set(gcf,'renderer','OpenGL') 37 | drawnow 38 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotRBN.m: -------------------------------------------------------------------------------- 1 | function plotRBN(individual,config) 2 | 3 | set(0,'currentFigure',config.figure_array(2)) 4 | 5 | for j = 1:config.num_reservoirs 6 | source_node = repmat(1:individual.nodes(j),config.k,1); 7 | source_node = source_node(:); 8 | G_in = [individual.RBN_node{j}.input]; 9 | G{j} = graph(source_node,G_in); 10 | subplot(1,config.num_reservoirs,j) 11 | plot(G{j}) 12 | end 13 | 14 | drawnow 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotRoR.m: -------------------------------------------------------------------------------- 1 | function plotRoR(figure1,best,loser,config) 2 | 3 | set(0,'currentFigure',figure1) 4 | for res_indx = 1:config.num_reservoirs 5 | 6 | ax1 = subplot(3,config.num_reservoirs*2,res_indx); 7 | imagesc(best.input_weights{res_indx}) 8 | colormap(ax1,bluewhitered) 9 | title('Input weights (best)') 10 | 11 | ax2 = subplot(3,config.num_reservoirs*2,config.num_reservoirs*2 + res_indx); 12 | imagesc(best.W{res_indx,res_indx}) 13 | colormap(ax2,bluewhitered) 14 | title('Hidden weights (best)') 15 | 16 | ax3 = subplot(3,config.num_reservoirs*2,config.num_reservoirs*4 + res_indx); 17 | imagesc(best.output_weights) 18 | colormap(ax3,bluewhitered) 19 | title('Output weights (best)') 20 | 21 | % plot loser 22 | ax1 = subplot(3,config.num_reservoirs*2,res_indx + config.num_reservoirs); 23 | imagesc(loser.input_weights{res_indx}) 24 | colormap(ax1,bluewhitered) 25 | title('Input weights (loser)') 26 | 27 | ax2 = subplot(3,config.num_reservoirs*2,config.num_reservoirs*2+ config.num_reservoirs + res_indx); 28 | imagesc(loser.W{res_indx,res_indx}) 29 | colormap(ax2,bluewhitered) 30 | title('Hidden weights (loser)') 31 | 32 | ax3 = subplot(3,config.num_reservoirs*2,config.num_reservoirs*4 + config.num_reservoirs + res_indx); 33 | imagesc(loser.output_weights) 34 | colormap(ax3,bluewhitered) 35 | title('Output weights (loser)') 36 | 37 | drawnow 38 | end 39 | 40 | -------------------------------------------------------------------------------- /Support files/other/Plots/plotSearch.m: -------------------------------------------------------------------------------- 1 | %% plot all behaviours in behaviour space 2 | function plotSearch(database, gen,config) 3 | 4 | all_behaviours = reshape([database.behaviours],length(config.metrics),length(database))'; 5 | 6 | set(0,'currentFigure',config.figure_array(1)) 7 | title(strcat('Gen:',num2str(gen))) 8 | v = 1:length(config.metrics); 9 | C = nchoosek(v,2); 10 | 11 | if size(C,1) > 3 12 | num_plot_x = 3; 13 | num_plot_y = ceil(size(C,1)/3); 14 | else 15 | num_plot_x = 1; 16 | num_plot_y = 3; 17 | end 18 | 19 | for i = 1:size(C,1) 20 | subplot(num_plot_x,num_plot_y,i) 21 | 22 | scatter(all_behaviours(:,C(i,1)),all_behaviours(:,C(i,2)),20,1:length(all_behaviours),'filled') 23 | 24 | xlabel(config.metrics(C(i,1))) 25 | ylabel(config.metrics(C(i,2))) 26 | colormap('copper') 27 | end 28 | 29 | drawnow 30 | 31 | end -------------------------------------------------------------------------------- /Support files/other/Plots/plotSearchwithTask.m: -------------------------------------------------------------------------------- 1 | %% plot all behaviours in behaviour space 2 | function plotSearchwithTask(database, gen, task_error ,config) 3 | 4 | %task_error(task_error > 0.5) = 0.5; 5 | set(gcf,'position',[0,492,1657,456]) 6 | 7 | for order = 1:1 8 | 9 | switch(order) 10 | case 1 11 | database_plot = database; 12 | task_error_plot = task_error; 13 | %title_label = 'added to database'; 14 | case 2 15 | [v,I] = sort(task_error,'descend'); 16 | database_plot = database(I); 17 | task_error_plot = v; 18 | title_label = 'descend'; 19 | case 3 20 | [v,I] = sort(task_error,'ascend'); 21 | database_plot = database(I); 22 | task_error_plot = v; 23 | title_label = 'ascend'; 24 | end 25 | 26 | 27 | all_behaviours = reshape([database_plot.behaviours],length(config.metrics),length(database_plot))'; 28 | 29 | set(0,'currentFigure',config.figure_array(1)) 30 | 31 | v = 1:length(config.metrics); 32 | C = nchoosek(v,2); 33 | % 34 | % if size(C,1) > 3 35 | % num_plot_x = ceil(size(C,1)/3); 36 | % num_plot_y = 3; 37 | % else 38 | % num_plot_x = 3; 39 | % num_plot_y = order; 40 | % end 41 | 42 | for i = 1:size(C,1) 43 | subplot(1,3,i + (order-1)*3) 44 | 45 | scatter(all_behaviours(:,C(i,1)),all_behaviours(:,C(i,2)),5,task_error_plot,'filled') 46 | 47 | xlabel(config.metrics(C(i,1))) 48 | ylabel(config.metrics(C(i,2))) 49 | colormap(jet) 50 | end 51 | 52 | %title(title_label) 53 | 54 | colorbar; 55 | drawnow 56 | 57 | end -------------------------------------------------------------------------------- /Support files/other/Plots/stdshade.m: -------------------------------------------------------------------------------- 1 | function stdshade(amatrix,alpha,acolor,F,smth) 2 | % usage: stdshading(amatrix,alpha,acolor,F,smth) 3 | % plot mean and sem/std coming from a matrix of data, at which each row is an 4 | % observation. sem/std is shown as shading. 5 | % - acolor defines the used color (default is red) 6 | % - F assignes the used x axis (default is steps of 1). 7 | % - alpha defines transparency of the shading (default is no shading and black mean line) 8 | % - smth defines the smoothing factor (default is no smooth) 9 | % smusall 2010/4/23 10 | if exist('acolor','var')==0 || isempty(acolor) 11 | acolor='r'; 12 | end 13 | if exist('F','var')==0 || isempty(F) 14 | F=1:size(amatrix,2); 15 | end 16 | if exist('smth','var'); if isempty(smth); smth=1; end 17 | else 18 | smth=1; %no smoothing by default 19 | end 20 | if ne(size(F,1),1) 21 | F=F'; 22 | end 23 | amean = nanmean(amatrix,1); %get man over first dimension 24 | if smth > 1 25 | amean = boxFilter(nanmean(amatrix,1),smth); %use boxfilter to smooth data 26 | end 27 | astd = nanstd(amatrix,[],1); % to get std shading 28 | % astd = nanstd(amatrix,[],1)/sqrt(size(amatrix,1)); % to get sem shading 29 | if exist('alpha','var')==0 || isempty(alpha) 30 | fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor,'linestyle','none'); 31 | acolor='k'; 32 | else 33 | fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor, 'FaceAlpha', alpha,'linestyle','none'); 34 | end 35 | if ishold==0 36 | check=true; else check=false; 37 | end 38 | hold on; 39 | plot(F,amean,'Color',acolor,'linewidth',1.5); %% change color or linewidth to adjust mean line 40 | if check 41 | hold off; 42 | end 43 | end 44 | function dataOut = boxFilter(dataIn, fWidth) 45 | % apply 1-D boxcar filter for smoothing 46 | dataStart = cumsum(dataIn(1:fWidth-2),2); 47 | dataStart = dataStart(1:2:end) ./ (1:2:(fWidth-2)); 48 | dataEnd = cumsum(dataIn(length(dataIn):-1:length(dataIn)-fWidth+3),2); 49 | dataEnd = dataEnd(end:-2:1) ./ (fWidth-2:-2:1); 50 | dataOut = conv(dataIn,ones(fWidth,1)/fWidth,'full'); 51 | dataOut = [dataStart,dataOut(fWidth:end-fWidth+1),dataEnd]; 52 | end 53 | -------------------------------------------------------------------------------- /Support files/other/Plots/weightStructure.m: -------------------------------------------------------------------------------- 1 | 2 | for i = 1:length(genotype) 3 | 4 | M = nonzeros(genotype(i).w);%full(genotype(i).w);%connectWeights{1,1} 5 | 6 | s = svd(M); 7 | 8 | tmp_rank_sum = 0; 9 | full_rank_sum = 0; 10 | 11 | e_rank = 1; 12 | for j = 1:length(s) 13 | full_rank_sum = full_rank_sum +s(j); 14 | while (tmp_rank_sum < full_rank_sum * 0.99) 15 | tmp_rank_sum = tmp_rank_sum + s(e_rank); 16 | e_rank= e_rank+1; 17 | end 18 | end 19 | 20 | W_rank(i) = sum(var(M))/length(M)% + sum(var(M,0,2));%sum(pdist(M))/size(M,1)*size(M,1);%e_rank-1; 21 | 22 | end 23 | 24 | figure 25 | scatter3(W_rank,kernel_rank, gen_rank) 26 | xlabel('var(W)') 27 | ylabel('KR') 28 | zlabel('GR') 29 | 30 | figure 31 | scatter3(W_rank,kernel_rank, MC) 32 | xlabel('var(W)') 33 | ylabel('KR') 34 | zlabel('MC') 35 | figure 36 | corrplot([W_rank' kernel_rank' gen_rank'],'type','Spearman') -------------------------------------------------------------------------------- /Support files/other/Prediction/learnFNNModel2.m: -------------------------------------------------------------------------------- 1 | function [meanTrainRMSE,meanTestRMSE,output_data,trainedModel] = learnFNNModel2(figureHandle,dataset,tests,NNsize) 2 | % task: set what task to train for. 3 | % test_thresh: set what limit should be bound on target data. 4 | % tests: how many models to train. 5 | 6 | samples = 1:size(dataset(1).inputs,1); 7 | 8 | %% pre processing 9 | x = dataset.inputs(samples,:)'; 10 | t = dataset.outputs(samples,:)'; 11 | 12 | % % remove outliers 13 | % pos_outliers = isoutlier(t); 14 | % t(pos_outliers) = []; 15 | % x(:,pos_outliers)= []; 16 | 17 | %assign data 18 | data = [x; t]; 19 | 20 | % partition data equally between training and test set 21 | [train_set,test_set]= preprocessCHARCdataset(data',70); 22 | 23 | fprintf('Preprocessed data........\n') 24 | 25 | %% train model 26 | for test = 1:tests 27 | [trainedModel{test}, ~,trainRMSE(test)] = trainFNNpredictor(train_set,NNsize); 28 | fprintf('Test = %d, RMSE = %.4f\n',test,trainRMSE(test)); 29 | end 30 | 31 | meanTrainRMSE = mean(trainRMSE); 32 | 33 | fprintf('Testing learnt models........\n') 34 | 35 | for test = 1:tests 36 | tempModel = trainedModel{test}; % get trained model - predicts performance of substrate given substrate behaviour 37 | y = tempModel(test_set(:,1:size(test_set,2)-1)'); % output of trained model, given metrics as inputs 38 | t = test_set(:,size(test_set,2)); % target error for given metrics 39 | testRMSE(test) = sqrt(mean((t-y').^2));%/var(t)); % calculate error of model 40 | end 41 | 42 | meanTestRMSE = mean(testRMSE); 43 | 44 | figure(figureHandle) 45 | scatter(y',t) 46 | line([0 1], [0 1],'Color','r') 47 | xlim([0 max(y)]) 48 | ylim([0 max(t)]) 49 | xlabel('Predicted') 50 | ylabel('Actual') 51 | 52 | output_data = [y' t]; 53 | 54 | -------------------------------------------------------------------------------- /Support files/other/Prediction/runBTreeScript.m: -------------------------------------------------------------------------------- 1 | 2 | %% Run through every task 3 | % Threshold at 1 4 | % Using 3 features 5 | for i = 1:4 6 | [rmseNN{i},maeNN{i},testRMSE{i},testMAE{i}] = learnRegressionModel(figure,1,i,10,'1',3); 7 | end 8 | % Using 11 features 9 | for i = 1:4 10 | [rmseNN{i},maeNN{i},testRMSE{i},testMAE{i}] = learnRegressionModel(figure,1,i,10,'1',11); 11 | end 12 | 13 | %% Threshold at 0.8 14 | % Using 3 features 15 | for i = 1:4 16 | [rmseNN{i},maeNN{i},testRMSE{i},testMAE{i}] = learnRegressionModel(figure,0.8,i,10,'0_8',3); 17 | end 18 | % Using 11 features 19 | for i = 1:4 20 | [rmseNN{i},maeNN{i},testRMSE{i},testMAE{i}] = learnRegressionModel(figure,0.8,i,10,'0_8',11); 21 | end -------------------------------------------------------------------------------- /Support files/other/Prediction/runFNNscript_AllSizes.m: -------------------------------------------------------------------------------- 1 | 2 | %% Run through every task 3 | % Threshold at 1 4 | % Using 3 features 5 | % for i = 1:4 6 | % learnFNNModel(figure,1,i,10,'1',3); 7 | % end 8 | % % Using 11 features 9 | % for i = 1:4 10 | % learnFNNModel(figure,1,i,10,'1',11); 11 | % end 12 | % 13 | % %% Threshold at 0.8 14 | % Using 3 features 15 | for i = 1:4 16 | learnFNNModel_ALL(figure,0.8,i,10,'0_8',3); 17 | end 18 | 19 | % Using 11 features - BEST!! 20 | for i = 1:4 21 | learnFNNModel_ALL(figure,0.8,i,10,'0_8',11); 22 | end -------------------------------------------------------------------------------- /Support files/other/Prediction/trainFNNpredictor.m: -------------------------------------------------------------------------------- 1 | function [net,maeNN,rmseNN] = trainFNNpredictor(data,NNsize) 2 | 3 | x = data(:,1:size(data,2)-1)'; 4 | t = data(:,size(data,2))'; 5 | 6 | % Choose a Training Function 7 | % For a list of all training functions type: help nntrain 8 | % 'trainlm' is usually fastest. 9 | % 'trainbr' takes longer but may be better for challenging problems. 10 | % 'trainscg' uses less memory. Suitable in low memory situations. 11 | trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. 12 | 13 | % Create a Fitting Network 14 | hiddenLayerSize = NNsize; 15 | net = fitnet(hiddenLayerSize,trainFcn); 16 | 17 | % Choose Input and Output Pre/Post-Processing Functions 18 | % For a list of all processing functions type: help nnprocess 19 | net.input.processFcns = {'removeconstantrows','mapstd'}; %'mapminmax',; 20 | net.output.processFcns = {'removeconstantrows','mapstd'}; %'mapminmax',; 21 | 22 | % Setup Division of Data for Training, Validation, Testing 23 | % For a list of all data division functions type: help nndivision 24 | net.divideFcn = 'dividerand'; % Divide data randomly 25 | net.divideMode = 'sample'; % Divide up every sample 26 | net.divideParam.trainRatio = 80/100; 27 | net.divideParam.valRatio = 10/100; 28 | net.divideParam.testRatio = 10/100; 29 | 30 | % Choose a Performance Function 31 | % For a list of all performance functions type: help nnperformance 32 | net.performFcn = 'mae'; % Mean Squared Error 33 | 34 | % Train the Network 35 | [net,tr] = train(net,x,t); 36 | 37 | % Test the Network 38 | y = net(x); 39 | % e = gsubtract(t,y); 40 | % performance = perform(net,t,y); 41 | 42 | % Recalculate Training, Validation and Test Performance 43 | % trainTargets = t .* tr.trainMask{1}; 44 | % valTargets = t .* tr.valMask{1}; 45 | % testTargets = t .* tr.testMask{1}; 46 | % trainPerformance = perform(net,trainTargets,y); 47 | % valPerformance = perform(net,valTargets,y); 48 | % testPerformance = perform(net,testTargets,y); 49 | 50 | maeNN = mae(t,y); 51 | rmseNN = sqrt(mean((t-y).^2)); 52 | %rmseNN = mean(abs(y./t)); % MAPE 53 | 54 | 55 | -------------------------------------------------------------------------------- /Support files/other/Prediction/trainMultiFNNpredictor.m: -------------------------------------------------------------------------------- 1 | function [net,maeNN,rmseNN] = trainMultiFNNpredictor(data,NNsize) 2 | 3 | x = data(:,1:size(data,2)-4)'; 4 | t = data(:,size(data,2)-3:size(data,2))'; 5 | 6 | % Choose a Training Function 7 | % For a list of all training functions type: help nntrain 8 | % 'trainlm' is usually fastest. 9 | % 'trainbr' takes longer but may be better for challenging problems. 10 | % 'trainscg' uses less memory. Suitable in low memory situations. 11 | trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. 12 | 13 | % Create a Fitting Network 14 | hiddenLayerSize = NNsize; 15 | net = fitnet(hiddenLayerSize,trainFcn); 16 | 17 | % Choose Input and Output Pre/Post-Processing Functions 18 | % For a list of all processing functions type: help nnprocess 19 | net.input.processFcns = {'removeconstantrows','mapminmax'}; 20 | net.output.processFcns = {'removeconstantrows','mapminmax'}; 21 | 22 | % Setup Division of Data for Training, Validation, Testing 23 | % For a list of all data division functions type: help nndivision 24 | net.divideFcn = 'dividerand'; % Divide data randomly 25 | net.divideMode = 'sample'; % Divide up every sample 26 | net.divideParam.trainRatio = 70/100; 27 | net.divideParam.valRatio = 15/100; 28 | net.divideParam.testRatio = 15/100; 29 | 30 | % Choose a Performance Function 31 | % For a list of all performance functions type: help nnperformance 32 | net.performFcn = 'mse'; % Mean Squared Error 33 | 34 | % Train the Network 35 | [net,tr] = train(net,x,t); 36 | 37 | % Test the Network 38 | y = net(x); 39 | e = gsubtract(t,y); 40 | performance = perform(net,t,y); 41 | 42 | % Recalculate Training, Validation and Test Performance 43 | trainTargets = t .* tr.trainMask{1}; 44 | valTargets = t .* tr.valMask{1}; 45 | testTargets = t .* tr.testMask{1}; 46 | trainPerformance = perform(net,trainTargets,y); 47 | valPerformance = perform(net,valTargets,y); 48 | testPerformance = perform(net,testTargets,y); 49 | 50 | maeNN = mae(t,y); 51 | rmseNN = sqrt(mean((t(:)-y(:)).^2)); 52 | 53 | 54 | -------------------------------------------------------------------------------- /Support files/other/Pruning/pruneDatabase.m: -------------------------------------------------------------------------------- 1 | %% Pruning test on database 2 | %[val,indx]= sort(reshape([database.behaviours],3,length(database))','descend'); 3 | %clearvars -except database config 4 | 5 | load('substrate_8_run1_networkSize_RoR_undirected0.mat') 6 | rng(1,'twister') 7 | num_iter = 4; 8 | ppm = ParforProgMon('Database complete: ', num_iter); 9 | parfor indx = 1:num_iter 10 | warning('off','all') 11 | individual = database(indx); 12 | for p = 1:5 13 | [individual,individual.behaviours,~,error] = pruning(@getMetrics,individual,database(indx).behaviours,[0 0 0.5],1000,0,config); 14 | fprintf('Node: %d, iter: %d, error: %d \n',indx,p,error) 15 | end 16 | 17 | pruned_database(indx) = individual; 18 | ppm.increment(); 19 | end 20 | 21 | %multi_prune = nnz(individual.W{1,1}); 22 | 23 | % rng(1,'twister') 24 | % individual = database(indx); 25 | % [individual,old_fitness] = pruning(individual,database(indx).behaviours,[0 0 0.5],10000,0,config); 26 | % 27 | % single_prune = nnz(individual.W{1,1}) 28 | 29 | 30 | % for p = 1:length(database) 31 | % [individual(p),old_fitness(p)] = pruning(database(p),[0 0 0.5],2500,0,config); 32 | % end 33 | % 34 | figure1 = figure; 35 | %figure2 = figure; 36 | 37 | %for i = 1:1 38 | % M = individual(i).W{1,1}; 39 | % if ~isempty(M) 40 | % [MATreordered{i},MATindices,MATcost] = reorder_matrix(M~=0,'line',0); 41 | % else 42 | % MATreordered{i} = M; 43 | % end 44 | 45 | for plot_indx = 1:length(pruned_database) 46 | 47 | M = pruned_database(plot_indx).W{1,1}; 48 | [MATreordered_b] = reorder_matrix(M~=0,'line',0); 49 | subplot(1,2,1) 50 | imagesc(M) 51 | colormap(gca,bluewhitered) 52 | title(num2str(pruned_database(plot_indx).behaviours)) 53 | 54 | [MATreordered_W] = reorder_matrix(abs(M),'line',0); 55 | subplot(1,2,2) 56 | imagesc(MATreordered_W) 57 | colormap(gca,bluewhitered) 58 | title(num2str(nnz(M))) 59 | drawnow 60 | pause(0.1) 61 | 62 | end 63 | %title(num2str(individual(i).behaviours)) 64 | %end -------------------------------------------------------------------------------- /Support files/other/adjustInputShape.m: -------------------------------------------------------------------------------- 1 | 2 | function [output_matrix_2d] = adjustInputShape(input_matrix_2d,width) 3 | 4 | f_pos = find(input_matrix_2d); 5 | 6 | % pad multipliers 7 | [x,y] = ndgrid(-2.1:(4.2/(2*width)):2.1); 8 | D=2/4*real((4-x.^2-y.^2).^0.5); 9 | D(ceil(size(D,1).^2/2)) = 0; 10 | 11 | % pad location 12 | w_adj = 2*width+1; 13 | pad_input_matrix_2d = zeros(size(input_matrix_2d)+w_adj+w_adj); 14 | pad_input_matrix_2d(w_adj+1:w_adj+length(input_matrix_2d),w_adj+1:w_adj+length(input_matrix_2d)) = input_matrix_2d; 15 | 16 | s=size(pad_input_matrix_2d); 17 | N=length(s); 18 | [c1{1:N}]=ndgrid(1:w_adj); 19 | c2(1:N)={ceil(w_adj/2)}; 20 | offsets=sub2ind(s,c1{:}) - sub2ind(s,c2{:}); 21 | 22 | B = pad_input_matrix_2d; 23 | 24 | for i = 1:length(f_pos) 25 | pos = f_pos(i) + w_adj*(size(input_matrix_2d,1) + 2*w_adj) + 2*(ceil(f_pos(i)/size(input_matrix_2d,1))-1)*w_adj + w_adj; 26 | B(pos + offsets) = B(pos + offsets) + D*B(pos); 27 | end 28 | 29 | output_matrix_2d = B(w_adj+1:end-w_adj,w_adj+1:end-w_adj); 30 | 31 | %output_matrix_2d = output_matrix_2d; 32 | % output_matrix_2d = output_matrix_2d 33 | % 34 | % max_value ; 35 | % min_value ; 36 | 37 | % subplot(1,2,1) 38 | % imagesc(input_matrix_2d) 39 | % colorbar 40 | % subplot(1,2,2) 41 | % imagesc(output_matrix_2d) 42 | % colorbar -------------------------------------------------------------------------------- /Support files/other/computeNRMSE.m: -------------------------------------------------------------------------------- 1 | function [NRMSE] = computeNRMSE(estimated_output, correct_output) 2 | % Computes the NRMSE between estimated and correct ESN outputs. 3 | % 4 | % input arguments: 5 | % estimatedOutput: array of size N1 x outputDimension, containing network 6 | % output data. Caution: it is assumed that these are un-rescaled and 7 | % un-shifted, that is, the transformations from the original data format 8 | % via esn.teacherScaling and esn.teacherShift are undone. This happens 9 | % automatically when the estimatedOutput was obtained from calling 10 | % test_esn. 11 | % 12 | % correctOutput: array of size N2 x outputDimension, containing the 13 | % original teacher data. 14 | % 15 | % output: 16 | % err: a row vector of NRMSE's, each corresponding to one of the output 17 | % dimensions. 18 | % 19 | % If length(correctOutput) > length(estimatedOutput), the first 20 | % elements from correctOutput are deleted. This accounts for cases where 21 | % some (nForgetPoints many) initial transient data points were cancelled 22 | % from estimatedOutput, as occurs in calls to test_esn. 23 | % 24 | % Version 1.0, June 6, 2006, H. Jaeger (as compute_error) 25 | % Revision 1, August 17, 2007, H. Jaeger (renamed to compute_NRMSE, 26 | % changed length to size) 27 | % Copyright: Fraunhofer IAIS 2006 / Patents pending 28 | 29 | [n_estimate_points, num_eval]= size(estimated_output) ; 30 | wash_out = size(correct_output, 1) - n_estimate_points ; 31 | correct_output = correct_output(wash_out+1:end,:) ; 32 | correctVariance = var(correct_output) ; 33 | meanerror = sum((estimated_output - correct_output).^2)/n_estimate_points ; 34 | NRMSE = (sqrt(meanerror./correctVariance)) ; 35 | 36 | %NRMSE = sqrt(immse(estimatedOutput,correctOutput)); 37 | for i = 1:num_eval 38 | if isnan(NRMSE(i)) 39 | NRMSE(i) = 1; 40 | end 41 | end 42 | 43 | if NRMSE > 1000 44 | NRMSE = 1; 45 | end 46 | 47 | %% 48 | NMSE = (sum((estimated_output - correct_output).^2)/n_estimate_points)/var(estimated_output); 49 | -------------------------------------------------------------------------------- /Support files/other/compute_NRMSE.m: -------------------------------------------------------------------------------- 1 | function [NRMSE] = compute_NRMSE(estimatedOutput, correctOutput) 2 | % Computes the NRMSE between estimated and correct ESN outputs. 3 | % 4 | % input arguments: 5 | % estimatedOutput: array of size N1 x outputDimension, containing network 6 | % output data. Caution: it is assumed that these are un-rescaled and 7 | % un-shifted, that is, the transformations from the original data format 8 | % via esn.teacherScaling and esn.teacherShift are undone. This happens 9 | % automatically when the estimatedOutput was obtained from calling 10 | % test_esn. 11 | % 12 | % correctOutput: array of size N2 x outputDimension, containing the 13 | % original teacher data. 14 | % 15 | % output: 16 | % err: a row vector of NRMSE's, each corresponding to one of the output 17 | % dimensions. 18 | % 19 | % If length(correctOutput) > length(estimatedOutput), the first 20 | % elements from correctOutput are deleted. This accounts for cases where 21 | % some (nForgetPoints many) initial transient data points were cancelled 22 | % from estimatedOutput, as occurs in calls to test_esn. 23 | % 24 | % Version 1.0, June 6, 2006, H. Jaeger (as compute_error) 25 | % Revision 1, August 17, 2007, H. Jaeger (renamed to compute_NRMSE, 26 | % changed length to size) 27 | % Copyright: Fraunhofer IAIS 2006 / Patents pending 28 | 29 | [nEstimatePoints, numEval]= size(estimatedOutput) ; 30 | nForgetPoints = size(correctOutput, 1) - nEstimatePoints ; 31 | correctOutput = correctOutput(nForgetPoints+1:end,:) ; 32 | correctVariance = var(correctOutput) ; 33 | meanerror = sum((estimatedOutput - correctOutput).^2)/nEstimatePoints ; 34 | NRMSE = (sqrt(meanerror./correctVariance)) ; 35 | 36 | %NRMSE = sqrt(immse(estimatedOutput,correctOutput)); 37 | for i = 1:numEval 38 | if isnan(NRMSE(i)) 39 | NRMSE(i) = 1; 40 | end 41 | end 42 | 43 | if NRMSE > 1000 44 | NRMSE = 1; 45 | end 46 | 47 | %% 48 | NMSE = (sum((estimatedOutput - correctOutput).^2)/nEstimatePoints)/var(estimatedOutput); 49 | -------------------------------------------------------------------------------- /Support files/other/convertCHARC2MAPelite.m: -------------------------------------------------------------------------------- 1 | 2 | function config = convertCHARC2MAPelite(config,database_genotype,all_databases,error, metrics, task) 3 | 4 | %% Task parameters 5 | config.discrete = 0; % binary input for discrete systems 6 | config.nbits = 16; % if using binary/discrete systems 7 | config.preprocess = 1; % basic preprocessing, e.g. scaling and mean variance 8 | config.dataSet = task; % Task to evolve for 9 | 10 | % get dataset 11 | [config] = selectDataset(config); 12 | 13 | % get any additional params stored in getDataSetInfo.m 14 | [config] = getDataSetInfo(config); 15 | 16 | config.metrics = metrics; 17 | 18 | for i = 1:length(database_genotype) 19 | config.database_genotype{i} = database_genotype(i); 20 | config.database_genotype{i}.metrics = all_databases(i,1:length(metrics)); 21 | config.database_genotype{i}.valError = error(i); 22 | end -------------------------------------------------------------------------------- /Support files/other/getError.m: -------------------------------------------------------------------------------- 1 | function error = getError(error_to_check,individual) 2 | switch(error_to_check) 3 | case 'train' 4 | error = [individual.train_error]; 5 | case 'val' 6 | error = [individual.val_error]; 7 | case'test' 8 | error = [individual.test_error]; 9 | case 'train&val' 10 | error = [individual.train_error] + [individual.val_error]; 11 | case 'val&test' 12 | error = [individual.val_error] + [individual.test_error]; 13 | case 'train&val&test' 14 | error = [individual.train_error] +[individual.val_error] +[individual.test_error]; 15 | end -------------------------------------------------------------------------------- /Support files/other/getLeakStates.m: -------------------------------------------------------------------------------- 1 | function states = getLeakStates(states,individual,input_sequence,config) 2 | 3 | for i= 1:config.num_reservoirs 4 | leak_states = zeros(size(states{i})); 5 | for n = 2:size(input_sequence,1) 6 | leak_states(n,:) = (1-individual.leak_rate(i))*leak_states(n-1,:)+ individual.leak_rate(i)*states{i}(n,:); 7 | end 8 | states{i} = leak_states; 9 | end -------------------------------------------------------------------------------- /Support files/other/iirFilterStates.m: -------------------------------------------------------------------------------- 1 | function filter_states = iirFilterStates(prev_states,filter_states,individual,config) 2 | 3 | %filter_states = zeros(size(states)); 4 | %prev_states = states; 5 | 6 | %for n = 1:size(states,1)-1 7 | 8 | for i = 1:size(prev_states,2) %cycle through neurons 9 | 10 | % equation: x_i(n+1) = (1/a_i,0) ((sum j=0 -> K) b_i,j * 11 | % u_i(n-j) - (sum j=0 -> K) a_i,j * u_i(n-j)) 12 | filter_states(i) = (individual.iir_weights{1}(i,:)*prev_states(config.iir_filter_order:-1:1,i) - individual.iir_weights{2}(i,1:end-1)*filter_states(config.iir_filter_order-1:-1:1,i))./individual.iir_weights{2}(i,1); 13 | 14 | end 15 | %end 16 | -------------------------------------------------------------------------------- /Support files/other/recursiveDivision.m: -------------------------------------------------------------------------------- 1 | function D = recursiveDivision(N) 2 | if N>1 3 | M = floor(N/2); 4 | D = [recursiveDivision(M),M]; 5 | else 6 | D = N; 7 | end 8 | end -------------------------------------------------------------------------------- /Support files/other/rk4_2.m: -------------------------------------------------------------------------------- 1 | function [t,Y] = rk4_2(F_xy,tspan,x0,Sm,h) 2 | 3 | % t = tspan(1):h:tspan(2); 4 | % y = y0; 5 | % 6 | % for n = 1:length(t)-1 7 | % 8 | % tp = t(n); 9 | % 10 | % k1 = dpdt(tp, y(n,:), Sm(n,:)); 11 | % 12 | % k2 = dpdt(tp + 0.5*h, y(n,:) + 0.5*k1*h, Sm(n,:)); 13 | % 14 | % k3 = dpdt(tp + 0.5*h, y(n,:) + 0.5*k2*h, Sm(n,:)); 15 | % 16 | % k4 = dpdt(tp + h, y(n,:) + k3*h, Sm(n,:)); 17 | % 18 | % y(n+1,:) = y(n,:) + (1/6)*((k1 + (2*k2) + (2*k3) + k4))*h; 19 | % 20 | % end 21 | 22 | t=tspan(1):h:tspan(2); 23 | y=zeros(length(x0),length(t)); 24 | y(:,1)=x0; 25 | 26 | for i=1:(length(t)-1) 27 | k1 = F_xy(t(i), y(:,i), Sm(i,:)); 28 | 29 | k2 = F_xy(t(i) + 0.5*h, y(:,i) + 0.5*h*k1, Sm(i,:)); 30 | 31 | k3 = F_xy((t(i) + 0.5*h), (y(:,i) + 0.5*h*k2), Sm(i,:)); 32 | 33 | k4 = F_xy((t(i) + h), (y(:,i) + k3*h), Sm(i,:)); 34 | 35 | y(:,i+1) = y(:,i) + (1/6)*(k1 + 2*k2 + 2*k3 + k4)*h; 36 | end 37 | 38 | Y=y'; -------------------------------------------------------------------------------- /Support files/other/saveData.m: -------------------------------------------------------------------------------- 1 | function saveData(database_history,database,quality,test,config,network_size) 2 | 3 | config.figure_array =[]; 4 | 5 | if test == 9 6 | save(strcat('substrate_',num2str(network_size),'_run',num2str(test),'_networkSize_',config.res_type,'_undirected',num2str(config.undirected)),... 7 | 'database_history','database','config','quality','-v7.3'); 8 | else 9 | save(strcat('substrate_',num2str(network_size),'_run',num2str(test),'_networkSize_',config.res_type,'_undirected',num2str(config.undirected)),... 10 | 'database_history','config','quality','-v7.3'); 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /Support files/other/testReservoir.asv: -------------------------------------------------------------------------------- 1 | function [genotype,testStates,testSequence] = testReservoir(genotype,config) 2 | 3 | statesExt = config.assessFcn(genotype,config.trainInputSequence,config); 4 | statesExtval = config.assessFcn(genotype,config.valInputSequence,config); 5 | 6 | if config.evolveOutputWeights %if W_out are evolved instead of trained 7 | outputSequence = statesExt*genotype.outputWeights; 8 | outputValSequence = statesExtval*genotype.outputWeights; 9 | genotype.trainError = calculateError(outputSequence,config.trainOutputSequence,config.nForgetPoints,config.errType); 10 | genotype.valError = calculateError(outputValSequence,config.valOutputSequence,config.nForgetPoints,config.errType); 11 | else 12 | 13 | % Find best reg parameter 14 | regTrainError = []; 15 | regValError =[];regWeights=[]; 16 | regParam = [10e-1 10e-3 10e-5 10e-7 10e-9]; 17 | 18 | for i = 1:length(regParam) 19 | %Train: tanspose is inversed compared to equation 20 | outputWeights = config.trainOutputSequence(config.nForgetPoints+1:end,:)'*statesExt*inv(statesExt'*statesExt + regParam(i)*eye(size(statesExt'*statesExt))); 21 | 22 | % Calculate trained output Y 23 | outputSequence = statesExt*outputWeights'; 24 | regTrainError(i,:) = calculateError(outputSequence,config.trainOutputSequence,config.nForgetPoints,config.errType); 25 | 26 | % Calculate trained output Y 27 | outputValSequence = statesExtval*outputWeights'; 28 | regValError(i,:) = calculateError(outputValSequence,config.valOutputSequence,config.nForgetPoints,config.errType); 29 | regWeights(i,:,:) =outputWeights; 30 | end 31 | 32 | [~, regIndx]= min(sum(regValError,2)); 33 | genotype.trainError = sum(regTrainError(regIndx,:)); 34 | genotype.valError = sum(regValError(regIndx,:)); 35 | %genotype.regParam = regParam(regIndx); 36 | 37 | genotype.outputWeights =reshape(regWeights(regIndx,:,:),size(regWeights,2),size(regWeights,3)); 38 | end 39 | 40 | %% Evaluate on test data 41 | testStates = config.assessFcn(genotype,config.testInputSequence,config); 42 | testSequence = testStates*genotype.outputWeights'; 43 | genotype.testError = sum(calculateError(testSequence,config.testOutputSequence,config.nForgetPoints,config.errType)); 44 | 45 | end -------------------------------------------------------------------------------- /Support files/other/testReservoir.m: -------------------------------------------------------------------------------- 1 | function [individual,test_states,test_sequence] = testReservoir(individual,config) 2 | 3 | train_states = config.assessFcn(individual,config.train_input_sequence,config,config.train_output_sequence); 4 | val_states = config.assessFcn(individual,config.val_input_sequence,config,config.val_output_sequence); 5 | 6 | %if W_out are evolved instead of trained 7 | if config.evolve_output_weights 8 | output_train_sequence = train_states*individual.output_weights; 9 | output_val_sequence = val_states*individual.output_weights; 10 | individual.train_error = calculateError(output_train_sequence,config.train_output_sequence,config); 11 | individual.val_error = calculateError(output_val_sequence,config.val_output_sequence,config); 12 | else 13 | 14 | % Find best reg parameter 15 | reg_train_error = []; 16 | reg_val_error =[];reg_weights=[]; 17 | reg_param = [10e-1 10e-3 10e-5 10e-7 10e-9 10e-11]; 18 | 19 | for i = 1:length(reg_param) 20 | %Train: tanspose is inversed compared to equation 21 | output_weights = config.train_output_sequence(config.wash_out+1:end,:)'*train_states*inv(train_states'*train_states + reg_param(i)*eye(size(train_states'*train_states))); 22 | 23 | % Calculate trained output Y 24 | output_train_sequence = train_states*output_weights'; 25 | reg_train_error(i,:) = calculateError(output_train_sequence,config.train_output_sequence,config); 26 | 27 | % Calculate trained output Y 28 | output_val_sequence = val_states*output_weights'; 29 | reg_val_error(i,:) = calculateError(output_val_sequence,config.val_output_sequence,config); 30 | reg_weights(i,:,:) =output_weights'; 31 | end 32 | 33 | [~, reg_indx]= min(sum(reg_val_error,2)); 34 | individual.train_error = sum(reg_train_error(reg_indx,:)); 35 | individual.val_error = sum(reg_val_error(reg_indx,:)); 36 | individual.output_weights =reshape(reg_weights(reg_indx,:,:),size(reg_weights,2),size(reg_weights,3)); 37 | 38 | %remove NaNs 39 | individual.output_weights(isnan(individual.output_weights)) = 0; 40 | end 41 | 42 | %% Evaluate on test data 43 | test_states = config.assessFcn(individual,config.test_input_sequence,config,config.test_output_sequence); 44 | test_sequence = test_states*individual.output_weights; 45 | individual.test_error = sum(calculateError(test_sequence,config.test_output_sequence,config)); 46 | 47 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/BZ reservoir/recombBZ.m: -------------------------------------------------------------------------------- 1 | %% recombBZ.m 2 | % Used to recombine BZ-specific parameters 3 | 4 | function loser = recombBZ(winner,loser,config) 5 | 6 | % params - input_scaling, leak_rate, 7 | W= winner.input_scaling(:); 8 | L = loser.input_scaling(:); 9 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 10 | L(pos) = W(pos); 11 | loser.input_scaling = reshape(L,size(loser.input_scaling)); 12 | 13 | W= winner.leak_rate(:); 14 | L = loser.leak_rate(:); 15 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 16 | L(pos) = W(pos); 17 | loser.leak_rate = reshape(L,size(loser.leak_rate)); 18 | 19 | W= winner.a(:); 20 | L = loser.a(:); 21 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 22 | L(pos) = W(pos); 23 | loser.a = reshape(L,size(loser.a)); 24 | 25 | W= winner.b(:); 26 | L = loser.b(:); 27 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 28 | L(pos) = W(pos); 29 | loser.b = reshape(L,size(loser.b)); 30 | 31 | W= winner.c(:); 32 | L = loser.c(:); 33 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 34 | L(pos) = W(pos); 35 | loser.c = reshape(L,size(loser.c)); 36 | 37 | % cycle through sub-reservoirs 38 | for i = 1:config.num_reservoirs 39 | 40 | for r = 1:3 41 | % input weights 42 | W= winner.input_weights{i,r}(:); 43 | L = loser.input_weights{i,r}(:); 44 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 45 | L(pos) = W(pos); 46 | loser.input_weights{i,r} = reshape(L,size(loser.input_weights{i,r})); 47 | 48 | % input widths 49 | W= winner.input_widths{i,r}(:); 50 | L = loser.input_widths{i,r}(:); 51 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 52 | L(pos) = W(pos); 53 | loser.input_widths{i,r} = reshape(L,size(loser.input_widths{i,r})); 54 | 55 | end 56 | end 57 | 58 | % for output weights 59 | if config.evolve_output_weights 60 | W= winner.output_weights(:); 61 | L = loser.output_weights(:); 62 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 63 | L(pos) = W(pos); 64 | loser.output_weights = reshape(L,size(loser.output_weights)); 65 | end 66 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/assocNeighbours.m: -------------------------------------------------------------------------------- 1 | function nodeUpdated = assocNeighbours(node, connectionMatrix) 2 | 3 | % ASSOCNEIGHBOURS Set the array "input" in the NODE structure-array according to the 4 | % network structure defined in CONNECTIONMATRIX. 5 | % 6 | % ASSOCNEIGHBOURS(NODE, CONNECTIONMATRIX) updates the fields "input" in the NODE 7 | % stucture-array according to the CONNECTIONMATRIX. 8 | % 9 | % Input: 10 | % node - 1 x n structure-array containing node information 11 | % connectionMatrix - n x n adjacent matrix (defined as in graph theory) 12 | % 13 | % Output: 14 | % nodeUpdated - 1 x n sturcture-array with updated node information ("input" fields) 15 | % 16 | 17 | 18 | % Author: Christian Schwarzer - SSC EPFL 19 | % CreationDate: 8.11.2002 LastModified: 20.01.2003 20 | 21 | 22 | if(nargin == 2) 23 | 24 | if(length(node) ~= length(connectionMatrix)) 25 | error('ConnectionMatrix does not correspond to NodeMatrix. Wrong dimension.') 26 | end 27 | 28 | nodeUpdated = node; 29 | 30 | for i=1:length(node) 31 | 32 | nodeUpdated(i).input = []; 33 | indices = find(connectionMatrix(:,i)); 34 | 35 | % get number of incoming connections from a particular node (multiplicity) 36 | for k=1:length(indices) 37 | multiplicity(k) = connectionMatrix(indices(k),i); 38 | end 39 | 40 | % set input vector 41 | for m=1:length(indices) 42 | nodeUpdated(i).input = [nodeUpdated(i).input repmat(indices(m),1,multiplicity(m))]; 43 | end 44 | 45 | end 46 | 47 | else 48 | error('Wrong number of arguments. Type: help assocNeighbours') 49 | end 50 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/assocRules.m: -------------------------------------------------------------------------------- 1 | function nodeUpdated = assocRules(node,rulesMatrix) 2 | 3 | % ASSOCRULES Set the array "rule" in the NODE structure-array according to the network's 4 | % transition logic rules defined in RULESMATRIX. 5 | % 6 | % ASSOCRULES(NODE, RULESMATRIX) updates the fields "rule" in the NODE 7 | % stucture-array according to the RULESMATRIX. 8 | % 9 | % Input: 10 | % node - 1 x n structure-array containing node information 11 | % rulesMatrix - 2^k x n matrix containing transition logic rules for each node 12 | % 13 | % Output: 14 | % nodeUpdated - 1 x n sturcture-array with updated node information ("rule" field) 15 | % 16 | 17 | 18 | % Author: Christian Schwarzer - SSC EPFL 19 | % CreationDate: 13.11.2002 LastModified: 20.01.2003 20 | 21 | if(nargin == 2) 22 | 23 | nodeUpdated = node; 24 | 25 | % set rule vector 26 | for i=1:length(node) 27 | nodeUpdated(i).rule = int8(rulesMatrix(:,i)); 28 | end 29 | 30 | else 31 | error('Wrong number of arguments. Type: help assocRules') 32 | end 33 | 34 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/evolveARBN.m: -------------------------------------------------------------------------------- 1 | function [nodeUpdated, timeStateMatrix] = evolveARBN(node, varargin) 2 | 3 | % EVOLVEARBN Develop network gradually K discrete time-steps according to ARBN (Asynchronous 4 | % Random Boolean Network) update scheme. 5 | % 6 | % EVOLVEARBN(NODE) advances all nodes in NODE one time-step in ARBN update mode. 7 | % 8 | % EVOLVEARBN(NODE, K) advances all nodes in NODE K time-steps in ARBN update mode. 9 | % 10 | % EVOLVEARBN(NODE, K, TK) advances all nodes in NODE K time-steps in ARBN update mode 11 | % and saves all TK steps all node-states and the timeStateMatrix to the disk. 12 | % 13 | % Input: 14 | % node - 1 x n structure-array containing node information 15 | % k - (Optional) Number of time-steps 16 | % tk - (Optional) Period for saving node-states/timeStateMatrix to disk. 17 | % 18 | % 19 | % Output: 20 | % nodeUpdated - 1 x n sturcture-array with updated node information 21 | % ("lineNumber", "state", "nextState") 22 | % timeStateMatrix - n x k+1 matrix containing calculated time-state evolution 23 | 24 | 25 | 26 | % Author: Christian Schwarzer - SSC EPFL 27 | % CreationDate: 20.11.2002 LastModified: 30.11.2018 (Matt Dale) 28 | 29 | input_sequence = varargin{1}; 30 | k = size(input_sequence,1); 31 | 32 | nodeUpdated = resetNodeStats(node); 33 | timeStateMatrix = zeros(length(nodeUpdated), k); 34 | timeStateMatrix(1:length(nodeUpdated),1) = getStateVector(nodeUpdated)'; 35 | 36 | n = length(nodeUpdated); 37 | 38 | % evolve network 39 | for i=1:k 40 | 41 | nodeSelected = randi([1 n],1,1); %pick node at random 42 | 43 | nodeUpdated = setLUTLines(nodeUpdated); 44 | nodeUpdated = setNodeNextState(nodeUpdated); 45 | 46 | nodeUpdated(nodeSelected).state = nodeUpdated(nodeSelected).nextState; 47 | nodeUpdated(nodeSelected).nbUpdates = nodeUpdated(nodeSelected).nbUpdates + 1; 48 | 49 | timeStateMatrix(1:length(nodeUpdated),i) = getStateVector(nodeUpdated)'; 50 | 51 | end 52 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/evolveDGARBN.m: -------------------------------------------------------------------------------- 1 | function [nodeUpdated, timeStateMatrix] = evolveDGARBN(node, varargin) 2 | 3 | % EVOLVEDGARBN Develop network gradually K discrete time steps according to DGARBN (Deterministic 4 | % Generalized Asynchronous Random Boolean Network) update scheme. 5 | % 6 | % EVOLVEDGARBN(NODE) advances all nodes in NODE one time-step in DGARBN update mode. 7 | % 8 | % EVOLVEDGARBN(NODE, K) advances all nodes in NODE K time-steps in DGARBN update mode. 9 | % 10 | % EVOLVEDGARBN(NODE, K, TK) advances all nodes in NODE K time-steps in DGARBN update mode 11 | % and saves all TK steps all node-states and the timeStateMatrix to the disk. 12 | % 13 | % Input: 14 | % node - 1 x n structure-array containing node information 15 | % k - (Optional) Number of time-steps 16 | % tk - (Optional) Period for saving node-states/timeStateMatrix to disk. 17 | % 18 | % Output: 19 | % nodeUpdated - 1 x n sturcture-array with updated node information 20 | % ("lineNumber", "state", "nextState") 21 | % timeStateMatrix - n x k+1 matrix containing calculated time-state evolution 22 | 23 | 24 | 25 | % Author: Christian Schwarzer - SSC EPFL 26 | % CreationDate: 20.11.2002 LastModified: 30.11.2018 (Matt Dale) 27 | 28 | 29 | input_sequence = varargin{1}; 30 | k = size(input_sequence,2); 31 | 32 | nodeUpdated = resetNodeStats(node); 33 | 34 | timeStateMatrix = zeros(length(nodeUpdated), k); 35 | timeStateMatrix(1:length(nodeUpdated),1) = getStateVector(nodeUpdated)'; 36 | 37 | n = length(nodeUpdated); 38 | 39 | % evolve network 40 | for i=1:k 41 | 42 | timeNow = i-1; 43 | nodeSelected = []; 44 | for j=1:n 45 | if(mod(timeNow,nodeUpdated(j).p) == nodeUpdated(j).q) 46 | nodeSelected = [nodeSelected j]; 47 | end 48 | end 49 | 50 | nodeUpdated = setLUTLines(nodeUpdated); 51 | nodeUpdated = setNodeNextState(nodeUpdated,genotype,input_sequence); 52 | 53 | for j=1:length(nodeSelected) 54 | nodeUpdated(nodeSelected(j)).state = nodeUpdated(nodeSelected(j)).nextState; 55 | nodeUpdated(nodeSelected(j)).nbUpdates = nodeUpdated(nodeSelected(j)).nbUpdates + 1; 56 | end 57 | 58 | timeStateMatrix(1:length(nodeUpdated),i) = getStateVector(nodeUpdated)'; 59 | 60 | end 61 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/getStateVector.m: -------------------------------------------------------------------------------- 1 | function stateVector = getStateVector(node) 2 | 3 | % GETSTATEVECTOR Return the states of the nodes in NODE as row vector. 4 | % 5 | % GETSTATEVECTOR(NODE) returns the states of all nodes in NODE as one row vector. 6 | % 7 | % Input: 8 | % node - 1 x n structure-array containing node information 9 | % 10 | % Output: 11 | % stateVector - 1 x n array with node states 12 | % 13 | 14 | % Author: Christian Schwarzer - SSC EPFL 15 | % CreationDate: 15.11.2002 LastModified: 08.08.2019 (matt dale) 16 | 17 | stateVector = zeros(1,length(node)); 18 | for i=1:length(node) 19 | stateVector(i) = node(i).state; 20 | end 21 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/initRules.m: -------------------------------------------------------------------------------- 1 | function rule = initRules(varargin) 2 | 3 | % INITRULES Generate a 2^k x n or 2^kMax x n matrix containing logic transition 4 | % rules for each node. 5 | % 6 | % INITRULES(N,K) generates a 2^K x N matrix defining logic transition rules 7 | % for each of the N nodes. A node with K incoming connections has 2^K possible 8 | % input vectors. Corresponding output (0 or 1) for each input vector is assigned 9 | % at random. 10 | % 11 | % INITRULES(RULESMATRIX) assigns given RULESMATRIX to rule. 12 | % 13 | % INITRULES(N, KMIN, KMAX, CONNECTIONMATRIX) generates a 2^KMAX x N matrix defining 14 | % logic transition rules for each of the N nodes. KMIN and KMAX define the minimum/ 15 | % maximum incoming connections per node. The actual number of incoming connections 16 | % is determined by inspection of CONNECTIONMATRIX. 17 | % 18 | % 19 | % Inputs: 20 | % n - (Optional) Number of nodes 21 | % k - (Optional) Number of connections per node 22 | % kMin - (Optional) Minimal number of connections per node 23 | % kMax - (Optional) Maximal number of connections per node 24 | % rulesMatrix - (Optional) 2^k x n matrix containing logic transition rules for each node 25 | % connectionMatrix - (Optional) n x n adjacent matrix (defined as in graph theory) 26 | % 27 | % Output: 28 | % rule - 2^k x n (2^kMax x n) matrix containing transition logic rules for each node 29 | % 30 | 31 | 32 | % Author: Christian Schwarzer - SSC EPFL 33 | % CreationDate: 6.11.2002 LastModified: 20.01.2003 34 | 35 | % one argument: rulesMatrix 36 | if(nargin == 1) 37 | 38 | rule = int8(varargin{1}); 39 | 40 | % two arguments: n,k 41 | elseif(nargin == 2) 42 | 43 | n = varargin{1}; 44 | k = varargin{2}; 45 | rule = int8(randi([0,1],2^k,n)); 46 | 47 | % four arguments: n,kMin,kMax,connectionMatrix 48 | elseif(nargin == 4) 49 | 50 | n = varargin{1}; 51 | kMin = varargin{2}; 52 | kMax = varargin{3}; 53 | connectionMatrix = varargin{4}; 54 | 55 | rule = int8(zeros(2^kMax,n)); 56 | for i=1:n 57 | s = sum(connectionMatrix(:,i)); 58 | rule(:,i)= [randi([0,1],1,2^s) zeros(1,2^kMax-2^s)]'; 59 | end 60 | 61 | else 62 | error('Wrong number of arguments. Type: help initRules') 63 | end 64 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/resetNodeStats.m: -------------------------------------------------------------------------------- 1 | function nodeUpdated = resetNodeStats(node) 2 | 3 | % RESETNODESTATS Reset all variables of the node structure which are involved in statistical evaluation to zero. 4 | % 5 | % RESETNODESTATS(NODE) resets all variables of the NODE structure which are involved in statistical evaluation to zero. 6 | % 7 | % Input: 8 | % node - 1 x n structure-array containing node information 9 | % 10 | % Output: 11 | % nodeUpdated - 1 x n structure-array containing updated node information ("nbUpdates"-field) 12 | 13 | 14 | % Author: Christian Schwarzer - SSC EPFL 15 | % CreationDate: 27.11.2002 LastModified: 20.01.2003 16 | 17 | nodeUpdated = node; 18 | for i=1:length(node) 19 | nodeUpdated(i).nbUpdates = 0; 20 | end 21 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/setLUTLines.m: -------------------------------------------------------------------------------- 1 | function nodeUpdated = setLUTLines(node) 2 | 3 | % SETLUTLINES Updates the "lineNumber" field of the NODE structure-array. 4 | % Make sure that assocNeighbours has been called on NODE before using this function. 5 | % 6 | % SETLUTLINES(NODE) For each node in NODE the states of the incoming nodes are 7 | % evaluated and transformed from binary to decimal representation (linenumber of the rulesmatrix). 8 | % This enables direct access into the rulesmatrix. The linenumber is stored in the "lineNumber" 9 | % field of the NODE structure-array. 10 | % 11 | % Input: 12 | % node - 1 x n structure-array containing node information 13 | % 14 | % Output: 15 | % nodeUpdated - 1 x n structure-array containing updated node information 16 | 17 | % Author: Christian Schwarzer - SSC EPFL 18 | % CreationDate: 13.11.2002 LastModified: 20.01.2003 19 | 20 | nodeUpdated = node; 21 | 22 | for i=1:length(node) 23 | 24 | statevector = zeros(1,length(node(i).input)); 25 | 26 | for k=1:length(node(i).input) 27 | statevector(k) = node(node(i).input(k)).state; 28 | end 29 | 30 | 31 | y = statevector(1); 32 | for k = 2:length(statevector) 33 | y = y.*2+statevector(k); 34 | end 35 | nodeUpdated(i).lineNumber = y+1; 36 | end 37 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Boolean Network Reservoir/setNodeNextState.m: -------------------------------------------------------------------------------- 1 | function nodeUpdated = setNodeNextState(node) 2 | 3 | % SETNODENEXTSTATE Look up next state for each node and update "nextState" field of the NODE 4 | % structure-array. Make sure that assocRules() has been called on NODE before using this function. 5 | % 6 | % SETNODENEXTSTATE(NODE) returns the updated node structure-array containing 7 | % next-state information for each node. 8 | % Next state information is stored in the "nextState" field of the NODE structure-array. 9 | % 10 | % Input: 11 | % node - 1 x n structure-array containing node information 12 | % genotype - 1 x 1 structure-array containing genotype information 13 | % inputSequence - 1 x n array containing input sequence 14 | % 15 | % Output: 16 | % nodeUpdated - 1 x n structure-array containing updated node information 17 | % 18 | % 19 | 20 | % Author: Christian Schwarzer - SSC EPFL 21 | % CreationDate: 13.11.2002 LastModified: 30.11.2018 (Matt Dale) 22 | 23 | nodeUpdated = node; 24 | 25 | for i=1:length(node) 26 | nodeUpdated(i).nextState = nodeUpdated(i).rule(nodeUpdated(i).lineNumber); 27 | end 28 | -------------------------------------------------------------------------------- /Support files/reservoir-type/DNA reservoir/createDNAreservoir.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterialMan/CHARC/0ff4eeea3890f443142436f07b49c4ca44ef6dd0/Support files/reservoir-type/DNA reservoir/createDNAreservoir.m -------------------------------------------------------------------------------- /Support files/reservoir-type/DNA reservoir/mutateDNA.m: -------------------------------------------------------------------------------- 1 | function genotype = mutateDNA(genotype,config) 2 | 3 | if rand < config.mutRate 4 | genotype.inputScaling = 2*rand; 5 | end 6 | 7 | % h the fraction of the reactor chamber that is well-mixed 8 | h = genotype.H(:); 9 | pos = randi([1 length(h)],ceil(config.mutRate*length(h)),1); 10 | h(pos) = rand(length(pos),1); 11 | genotype.H = reshape(h,size(genotype.H)); 12 | 13 | % volume of the reactor; V in nL 14 | v = genotype.V(:).*1e+8; 15 | pos = randi([1 length(v)],ceil(config.mutRate*length(v)),1); 16 | v(pos) = rand(length(pos),1); 17 | genotype.V = reshape(v,size(genotype.V)).*1e-8; 18 | 19 | % initial concentrations: S 20 | P0 = genotype.P0(:); 21 | pos = randi([1 length(P0)],ceil(config.mutRate*length(P0)),1); 22 | P0(pos) = randi([0 1000],length(pos),1); 23 | genotype.P0 = reshape(P0,size(genotype.P0)); 24 | 25 | % initial concentrations: P 26 | S0 = genotype.S0(:); 27 | pos = randi([1 length(S0)],ceil(config.mutRate*length(S0)),1); 28 | S0(pos) = randi([0 1000],length(pos),1); 29 | genotype.S0 = reshape(S0,size(genotype.S0)); 30 | 31 | % gate concentrations 32 | GateCon = genotype.GateCon(:); 33 | pos = randi([1 length(GateCon)],ceil(config.mutRate*length(GateCon)),1); 34 | GateCon(pos) = randi([0 2500],length(pos),1); 35 | genotype.GateCon = reshape(GateCon,size(genotype.GateCon)); 36 | 37 | 38 | % input weights 39 | w_in = genotype.w_in(:); 40 | pos = randi([1 length(w_in)],ceil(config.mutRate*length(w_in)),1); 41 | if config.restricedWeight 42 | w_in(pos) = datasample(0.2:0.2:1,length(pos));%2*rand(length(pos),1)-1; 43 | else 44 | w_in(pos) = 2*rand(length(pos),1)-1; 45 | end 46 | genotype.w_in = reshape(w_in,size(genotype.w_in)); 47 | 48 | % % input_loc 49 | % for i = 1:length(genotype.input_loc) 50 | % if rand < config.mutRate 51 | % genotype.input_loc(i) = round(rand); 52 | % end 53 | % end 54 | % genotype.totalInputs = sum(genotype.input_loc); 55 | 56 | 57 | if config.evolvedOutputStates 58 | 59 | if rand < config.mutRate %not really used, yet 60 | genotype.state_perc = rand; 61 | end 62 | 63 | % state_loc 64 | for i = 1:length(genotype.state_loc) 65 | if rand < config.mutRate 66 | genotype.state_loc(i) = round(rand); 67 | end 68 | end 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /Support files/reservoir-type/DNA reservoir/recombDNA.m: -------------------------------------------------------------------------------- 1 | function l = recombDNA(w,l,config) 2 | 3 | if rand < config.recRate 4 | l.inputScaling = w.inputScaling; 5 | end 6 | 7 | % h the fraction of the reactor chamber that is well-mixed 8 | Winner= w.H(:); 9 | Loser = l.H(:); 10 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 11 | Loser(pos) = Winner(pos); 12 | l.H = reshape(Loser,size(l.H)); 13 | 14 | % volume of the reactor; V in nL 15 | Winner= w.V(:); 16 | Loser = l.V(:); 17 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 18 | Loser(pos) = Winner(pos); 19 | l.V = reshape(Loser,size(l.V)); 20 | 21 | % initial concentrations: P 22 | Winner= w.P0(:); 23 | Loser = l.P0(:); 24 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 25 | Loser(pos) = Winner(pos); 26 | l.P0 = reshape(Loser,size(l.P0)); 27 | 28 | % initial concentrations: S 29 | Winner= w.S0(:); 30 | Loser = l.S0(:); 31 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 32 | Loser(pos) = Winner(pos); 33 | l.S0 = reshape(Loser,size(l.S0)); 34 | 35 | % gate concentrations 36 | Winner= w.GateCon(:); 37 | Loser = l.GateCon(:); 38 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 39 | Loser(pos) = Winner(pos); 40 | l.GateCon = reshape(Loser,size(l.GateCon)); 41 | 42 | % input weights 43 | Winner= w.w_in(:); 44 | Loser = l.w_in(:); 45 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 46 | Loser(pos) = Winner(pos); 47 | l.w_in = reshape(Loser,size(l.w_in)); 48 | 49 | % input locations 50 | % Winner= w.input_loc; 51 | % Loser = l.input_loc; 52 | % pos = randi([1 length(Loser)],round(config.recRate*length(Loser)),1); 53 | % Loser(pos) = Winner(pos); 54 | % l.input_loc = Loser; 55 | 56 | % location of states to use - i.e. subsample states 57 | if config.evolvedOutputStates 58 | Winner= w.state_loc; 59 | Loser = l.state_loc; 60 | pos = randi([1 length(Loser)],ceil(config.recRate*length(Loser)),1); 61 | Loser(pos) = Winner(pos); 62 | l.state_loc = Loser; 63 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/DNA reservoir/rk4_2.m: -------------------------------------------------------------------------------- 1 | function [t,y] = rk4_2(dpdt,tspan,y0,Sm,h) 2 | 3 | if nargin < 4, error('at least 4 input arguments required'), end 4 | if any(diff(tspan)<=0), error('tspan not ascending order'), end 5 | 6 | t = tspan(1):h:tspan(2); 7 | y = y0; 8 | 9 | for n = 1:length(t)-1 10 | 11 | tp = t(n); 12 | 13 | k1 = dpdt(tp, y(n,:), Sm(n,:)); 14 | 15 | k2 = dpdt(tp + 0.5*h, y(n,:) + 0.5*k1*h, Sm(n,:)); 16 | 17 | k3 = dpdt(tp + 0.5*h, y(n,:) + 0.5*k2*h, Sm(n,:)); 18 | 19 | k4 = dpdt(tp + h, y(n,:) + k3*h, Sm(n,:)); 20 | 21 | y(n+1,:) = y(n,:) + (1/6)*((k1 + (2*k2) + (2*k3) + k4))*h; 22 | 23 | end 24 | 25 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Delay-Line Reservoirs/mutateDL.m: -------------------------------------------------------------------------------- 1 | function offspring = mutateDL(offspring,config) 2 | 3 | % params - input scaling and leak rate 4 | input_scaling = offspring.input_scaling(:); 5 | pos = randi([1 length(input_scaling)],rand < 0.25,1); 6 | input_scaling(pos) = 2*rand(length(pos),1)-1; % between [-1, 1] 7 | offspring.input_scaling = reshape(input_scaling,size(offspring.input_scaling)); 8 | 9 | leak_rate = offspring.leak_rate(:); 10 | pos = randi([1 length(leak_rate)],rand < 0.25,1); 11 | leak_rate(pos) = rand(length(pos),1); % between [0, 1] 12 | offspring.input_scaling = reshape(leak_rate,size(offspring.leak_rate)); 13 | 14 | % DL parameters 15 | eta = offspring.eta(:); 16 | pos = randi([1 length(eta)],rand < 0.25,1); 17 | eta(pos) = rand(length(pos),1); % between [0, 1] 18 | offspring.eta = reshape(eta,size(offspring.eta)); 19 | 20 | gamma = offspring.gamma(:); 21 | pos = randi([1 length(gamma)],rand < 0.25,1); 22 | gamma(pos) = rand(length(pos),1); % between [0, 1] 23 | offspring.gamma = reshape(gamma,size(offspring.gamma)); 24 | 25 | p = offspring.p(:); 26 | pos = randi([1 length(p)],rand < 0.25,1); 27 | p(pos) = max([1 round(20*rand(length(pos),1))]); % between [1, 20] 28 | offspring.p = reshape(p,size(offspring.p)); 29 | 30 | % cycle through all sub-reservoirs 31 | for i = 1:config.num_reservoirs 32 | 33 | % input weights 34 | input_weights = offspring.input_weights{i}; 35 | pos = randi([1 length(input_weights)],ceil(config.mut_rate*length(input_weights)),1); 36 | for n = 1:length(pos) 37 | if rand < 0.5 % 50% chance to zero weight 38 | input_weights(pos(n)) = 0; 39 | else 40 | if config.binary_weights 41 | input_weights(pos(n)) = sign(2*rand-1); 42 | else 43 | input_weights(pos(n)) = 2*rand-1; % between [-1, 1] 44 | end 45 | end 46 | end 47 | offspring.input_weights{i} = reshape(input_weights,size(offspring.input_weights{i})); 48 | end 49 | 50 | % mutate output weights 51 | if config.evolve_output_weights 52 | output_weights = offspring.output_weights(:); 53 | pos = randi([1 length(output_weights)],ceil(config.mut_rate*length(output_weights)),1); 54 | for n = 1:length(pos) 55 | if rand > 0.75 % 75% chance to zero weight 56 | output_weights(pos(n)) = 0; 57 | else 58 | output_weights(pos(n)) = 2*rand-1; 59 | end 60 | end 61 | offspring.output_weights = reshape(output_weights,size(offspring.output_weights)); 62 | end 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Delay-Line Reservoirs/recombDL.m: -------------------------------------------------------------------------------- 1 | function loser = recombDL(winner,loser,config) 2 | 3 | % params - input_scaling, leak_rate, 4 | W= winner.input_scaling(:); 5 | L = loser.input_scaling(:); 6 | pos = randi([1 length(L)],ceil(config.rec_rate*length(L)),1); 7 | L(pos) = W(pos); 8 | loser.input_scaling = reshape(L,size(loser.input_scaling)); 9 | 10 | W= winner.leak_rate(:); 11 | L = loser.leak_rate(:); 12 | pos = randi([1 length(L)],ceil(config.rec_rate*length(L)),1); 13 | L(pos) = W(pos); 14 | loser.leak_rate = reshape(L,size(loser.leak_rate)); 15 | 16 | % cycle through sub-reservoirs 17 | for i = 1:config.num_reservoirs 18 | 19 | % input weights 20 | W= winner.input_weights{i}(:); 21 | L = loser.input_weights{i}(:); 22 | pos = randi([1 length(L)],ceil(config.rec_rate*length(L)),1); 23 | L(pos) = W(pos); 24 | loser.input_weights{i} = reshape(L,size(loser.input_weights{i})); 25 | 26 | % reservoir parameters 27 | temp_winner = [winner.eta(i) winner.gamma(i) winner.p(i)]; 28 | temp_loser = [loser.eta(i) loser.gamma(i) loser.p(i)]; 29 | pos = randi([1 length(temp_loser)],ceil(config.rec_rate*length(temp_loser)),1); 30 | temp_loser(pos) = temp_winner(pos); 31 | 32 | loser.eta(i) = temp_loser(1); 33 | loser.gamma(i) = temp_loser(2); 34 | loser.p(i) = temp_loser(3); 35 | 36 | end 37 | 38 | % for output weights 39 | if config.evolve_output_weights 40 | W= winner.output_weights(:); 41 | L = loser.output_weights(:); 42 | pos = randi([1 length(L)],ceil(config.rec_rate*length(L)),1); 43 | L(pos) = W(pos); 44 | loser.output_weights = reshape(L,size(loser.output_weights)); 45 | end 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Support files/reservoir-type/ELM/collectELMStates.m: -------------------------------------------------------------------------------- 1 | function [final_states,individual] = collectELMStates(individual,input_sequence,config,target_output) 2 | 3 | %% if single input entry, add previous state 4 | if size(input_sequence,1) == 1 5 | input_sequence = [zeros(size(input_sequence)); input_sequence]; 6 | end 7 | 8 | for i= 1:config.num_reservoirs 9 | if size(input_sequence,1) == 2 10 | states{i} = individual.last_state{i}; 11 | else 12 | states{i} = zeros(size(input_sequence,1),individual.nodes(i)); 13 | end 14 | x{i} = zeros(size(input_sequence,1),individual.nodes(i)); 15 | end 16 | 17 | % preassign activation function calls 18 | if size(individual.activ_Fcn,2) > 1 19 | for i= 1:config.num_reservoirs 20 | for p = 1:length(config.activ_list) 21 | index{i,p} = findActiv({individual.activ_Fcn{i,:}},config.activ_list{p}); 22 | end 23 | end 24 | end 25 | 26 | %equation: x(n) = f(Win*u(n) + S) 27 | for n = 2:size(input_sequence,1) 28 | 29 | for i= 1:config.num_reservoirs 30 | 31 | if i == 1 32 | input = (individual.input_weights{i}*individual.input_scaling(i))*([individual.bias_node input_sequence(n,:)])'; 33 | else 34 | indx = logical(eye(size(individual.W{i,i},1),size(individual.W{i,i},2))); 35 | individual.W{i,i}(indx) = 0; 36 | input = ([individual.bias_node states{i-1}(n,:)]*individual.W{i,i}'*individual.W_scaling(i,i))'; 37 | end 38 | 39 | if size(individual.activ_Fcn,2) > 1 40 | for p = 1:length(config.activ_list) 41 | states{i}(n,index{i,p}) = config.activ_list{p}(input(index{i,p},:)); 42 | end 43 | else 44 | states{i}(n,:) = individual.activ_Fcn{1}(input); 45 | end 46 | 47 | end 48 | 49 | end 50 | 51 | 52 | if config.leak_on 53 | states = getLeakStates(states,individual,input_sequence,config); 54 | end 55 | 56 | % concat all states for output weights 57 | final_states = []; 58 | for i= 1:config.num_reservoirs 59 | final_states = [final_states states{i}]; 60 | 61 | %assign last state variable 62 | individual.last_state{i} = states{i}(end,:); 63 | end 64 | 65 | if config.add_input_states == 1 66 | final_states = [final_states input_sequence]; 67 | end 68 | 69 | if size(input_sequence,1) == 2 70 | final_states = final_states(end,:); % remove washout 71 | else 72 | final_states = final_states(config.wash_out+1:end,:); % remove washout 73 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/assessGraphReservoir.m: -------------------------------------------------------------------------------- 1 | function [final_states,individual] = assessGraphReservoir(individual,input_sequence,config,target_output) 2 | 3 | %if single input entry, add previous state 4 | if size(input_sequence,1) == 1 5 | input_sequence = [zeros(size(input_sequence)); input_sequence]; 6 | end 7 | 8 | for i= 1:config.num_reservoirs 9 | if size(input_sequence,1) == 2 10 | states{i} = individual.last_state{i}; 11 | else 12 | states{i} = zeros(size(input_sequence,1),individual.nodes(i)); 13 | end 14 | x{i} = zeros(size(input_sequence,1),individual.nodes(i)); 15 | 16 | end 17 | 18 | % preassign activation function calls 19 | if size(individual.activ_Fcn,2) > 1 20 | for i= 1:config.num_reservoirs 21 | for p = 1:length(config.activ_list) 22 | index{i,p} = findActiv({individual.activ_Fcn{i,:}},config.activ_list{p}); 23 | end 24 | end 25 | end 26 | 27 | %% collect states 28 | for n = 2:size(input_sequence,1) 29 | 30 | for i= 1:config.num_reservoirs 31 | 32 | for k= 1:config.num_reservoirs 33 | x{i}(n,:) = x{i}(n,:) + ((individual.W{i,k}*individual.W_scaling(i,k))*states{k}(n-1,:)')'; 34 | end 35 | 36 | if size(individual.activ_Fcn,2) > 1 37 | for p = 1:length(config.activ_list) 38 | states{i}(n,index{i,p}) = individual.activ_Fcn{p}(((individual.input_weights{i}(index{i,p},:)*individual.input_scaling(i))*([individual.bias_node input_sequence(n,:)])')+ x{i}(n,index{i,p})'); 39 | end 40 | else 41 | states{i}(n,:) = individual.activ_Fcn{1}(((individual.input_weights{i}*individual.input_scaling(i))*([individual.bias_node input_sequence(n,:)])')+ x{i}(n,:)'); 42 | end 43 | end 44 | end 45 | 46 | % get leak states 47 | if config.leak_on 48 | states = getLeakStates(states,individual,input_sequence,config); 49 | end 50 | 51 | % concat all states for output weights 52 | final_states = []; 53 | for i= 1:config.num_reservoirs 54 | final_states = [final_states states{i}]; 55 | 56 | %assign last state variable 57 | individual.last_state{i} = states{i}(end,:); 58 | end 59 | 60 | % concat input states 61 | if config.add_input_states == 1 62 | final_states = [final_states input_sequence]; 63 | end 64 | 65 | if size(input_sequence,1) == 2 66 | final_states = final_states(end,:); % remove washout 67 | else 68 | final_states = final_states(config.wash_out+1:end,:); % remove washout 69 | end 70 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/cubelet.m: -------------------------------------------------------------------------------- 1 | function x = cubelet 2 | % x = cubelet 3 | % 8-by-3 array of vertices of a unit cube. 4 | x = [-1 -1 -1 5 | 1 -1 -1 6 | -1 1 -1 7 | 1 1 -1 8 | -1 -1 1 9 | 1 -1 1 10 | -1 1 1 11 | 1 1 1]; 12 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/cylinder.m: -------------------------------------------------------------------------------- 1 | s = []; 2 | t=[]; 3 | N = 8; 4 | N_rings =N; 5 | 6 | %rings 7 | for i = 1:N_rings 8 | s(i,:) = (i-1)*N+1:i*N; 9 | t(i,:) = [(i-1)*N+2:i*N (i-1)*N+1]; 10 | end 11 | 12 | %connecting rings 13 | for i = N_rings+1:N_rings*2-1 14 | s(i,:) = s(i-(N_rings-1),:); 15 | t(i,:) = s(i-N_rings,:); 16 | end 17 | %last ring 18 | s(i+1,:) = s(1,:); 19 | t(i+1,:) = s(i,:); 20 | 21 | G = graph(s(:),t(:)); 22 | plot(G,'Layout','subspace3') 23 | 24 | %plot(G) -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/getShape.m: -------------------------------------------------------------------------------- 1 | %% called from getDataSetInfo 2 | % Create graph structure G to use 3 | 4 | function [config,new_num_nodes] = getShape(config) 5 | 6 | 7 | for graph_indx = 1:length(config.num_nodes) 8 | 9 | num_nodes= config.num_nodes(graph_indx); 10 | graph_type = config.graph_type{graph_indx}; 11 | 12 | switch(graph_type) 13 | 14 | case 'Bucky' 15 | G = graph(bucky); 16 | config.plot_3d = 1; % plot graph in 3D. 17 | 18 | case 'L' 19 | A = delsq(numgrid('L',num_nodes +2)); 20 | G = graph(A,'omitselfloops'); 21 | config.plot_3d = 0; % plot graph in 3D. 22 | 23 | case 'Hypercube' 24 | A = hypercube(num_nodes); 25 | G = graph(A); 26 | config.plot_3d = 1; % plot graph in 3D. 27 | 28 | case 'Torus' 29 | config.rule_type = 'Moores'; 30 | config.torus_rings = config.num_nodes; 31 | G = torusGraph(num_nodes,config.self_loop(graph_indx),config); 32 | config.plot_3d = 1; % plot graph in 3D. 33 | 34 | case 'Barbell' 35 | load barbellgraph.mat 36 | G = graph(A,'omitselfloops'); 37 | config.plot_3d = 0; % plot graph in 3D. 38 | 39 | case {'basicLattice','partialLattice','fullLattice','basicCube','partialCube','fullCube','ensembleLattice', 'ensembleCube','ensembleShape'} 40 | G = createLattice(num_nodes,graph_type,config.self_loop(graph_indx),config.num_reservoirs); 41 | config.plot_3d = 0; % plot graph in 3D. 42 | 43 | case 'Ring' 44 | config.rule_type = 0; 45 | config.torus_rings = 1; 46 | G = torusGraph(num_nodes,config.self_loop(graph_indx),config); 47 | config.plot_3d = 0; % plot graph in 3D. 48 | 49 | otherwise 50 | error('Requires a substrate shape. Check graph type.') 51 | end 52 | 53 | config.G{graph_indx} = G; 54 | new_num_nodes(graph_indx) = size(config.G{graph_indx}.Nodes,1); 55 | end 56 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/hypercube.m: -------------------------------------------------------------------------------- 1 | function A = hypercube(d) 2 | % hypercube(d) is a logical adjacency matrix for a d-dimensional hypercube. 3 | pow2 = 2.^(0:d-1); 4 | f2b = @(j) floor(rem(j./pow2,2)); % flint to binary 5 | b2f = @(b) b*pow2'; % binary to flint 6 | n = 2^d; 7 | A = zeros(n,n,'logical'); 8 | for j = 0:n-1 9 | % Convert column index to binary. 10 | b = f2b(j); 11 | % Flip bits to get corresponding row indices. 12 | for i = 1:d 13 | b(i) = ~b(i); 14 | k = b2f(b); 15 | b(i) = ~b(i); 16 | A(k+1,j+1) = 1; 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/plotGraphNeuron.m: -------------------------------------------------------------------------------- 1 | function plotGraphNeuron(figure1,individual,best_indv) 2 | 3 | set(0,'currentFigure',figure1) 4 | 5 | for graph_indx = 1:size(individual.G,1) 6 | 7 | subplot(2,size(individual.G,1),graph_indx) 8 | if config.plot3d 9 | p = plot(individual(best_indv).G{graph_indx},'NodeLabel',{},'Layout','force3'); 10 | else 11 | p = plot(individual(best_indv).G{graph_indx},'NodeLabel',{},'Layout','force'); 12 | end 13 | p.NodeColor = 'black'; 14 | p.MarkerSize = 1; 15 | if ~config.directedGraph 16 | p.EdgeCData = individual(best_indv).G{graph_indx}.Edges.Weight; 17 | end 18 | highlight(p,logical(individual(best_indv).input_loc),'NodeColor','g','MarkerSize',3) 19 | colormap(bluewhitered) 20 | xlabel('Best weights') 21 | 22 | % plot loser 23 | subplot(2,size(individual.G,1),size(individual.G,1)+graph_indx) 24 | if config.plot3d 25 | p = plot(individual(loser).G,'NodeLabel',{},'Layout','force3'); 26 | else 27 | p = plot(individual(loser).G,'NodeLabel',{},'Layout','force'); 28 | end 29 | if ~config.directedGraph 30 | p.EdgeCData = individual(loser).G.Edges.Weight; 31 | end 32 | p.NodeColor = 'black'; 33 | p.MarkerSize = 1; 34 | highlight(p,logical(individual(loser).input_loc),'NodeColor','g','MarkerSize',3) 35 | colormap(bluewhitered) 36 | xlabel('Loser weights') 37 | 38 | pause(0.01) 39 | drawnow 40 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/Graph Reservoir/torusGraph.m: -------------------------------------------------------------------------------- 1 | function G = torusGraph(Nodes,self_loop,config) 2 | %% N > 8 tends to visualise better 3 | 4 | s = []; 5 | t=[]; 6 | N_rings = config.torus_rings; 7 | 8 | %rings 9 | for i = 1:N_rings 10 | s(i,:) = (i-1)*Nodes+1:i*Nodes; 11 | t(i,:) = [(i-1)*Nodes+2:i*Nodes (i-1)*Nodes+1]; 12 | end 13 | 14 | %connecting rings 15 | if N_rings > 1 16 | for i = N_rings+1:N_rings*2-1 17 | s(i,:) = s(i-(N_rings-1),:); 18 | t(i,:) = s(i-N_rings,:); 19 | end 20 | 21 | %last ring 22 | s(i+1,:) = s(1,:); 23 | t(i+1,:) = s(i,:); 24 | end 25 | 26 | % looks odd if N <= N_rings 27 | if strcmp('Moores',config.rule_type) 28 | for j = 1:N_rings 29 | %top right 30 | s(j+N_rings*2,:) = s(N_rings+j,:); 31 | t(j+N_rings*2,1:end-1) = t(N_rings+j,1:end-1)+1; 32 | t(j+N_rings*2,end) = t(j+N_rings*2,1)-1; 33 | 34 | %tbottom right 35 | s(j+N_rings*3,:) = s(N_rings+j,:); 36 | t(j+N_rings*3,2:end) = t(N_rings+j,2:end)-1; 37 | t(j+N_rings*3,1) = t(j+N_rings*3,end)+1; 38 | 39 | end 40 | end 41 | 42 | %add self connections 43 | if self_loop 44 | for j = 1:N_rings 45 | s = [s; (j-1)*Nodes+1:j*Nodes]; 46 | t = [t; (j-1)*Nodes+1:j*Nodes]; 47 | end 48 | end 49 | 50 | G = graph(s(:),t(:)); 51 | 52 | %% plot torus 53 | % figure 54 | % h = plot(G,'Layout','subspace3') 55 | 56 | %label nodes 57 | % for i = 1:size(G.Nodes,1) 58 | % labelnode(h,i,{num2str(i)}) 59 | % end -------------------------------------------------------------------------------- /Support files/reservoir-type/Hardware/CNT/recombCNT.m: -------------------------------------------------------------------------------- 1 | %% Infection phase 2 | function loser = recombCNT(winner,loser,config) 3 | 4 | % params - input_scaling, leak_rate, 5 | W= winner.input_scaling(:); 6 | L = loser.input_scaling(:); 7 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 8 | L(pos) = W(pos); 9 | loser.input_scaling = reshape(L,size(loser.input_scaling)); 10 | 11 | W= winner.leak_rate(:); 12 | L = loser.leak_rate(:); 13 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 14 | L(pos) = W(pos); 15 | loser.leak_rate = reshape(L,size(loser.leak_rate)); 16 | 17 | 18 | % cycle through sub-reservoirs 19 | for i = 1:config.num_reservoirs 20 | 21 | % input weights 22 | W= winner.input_weights{i}(:); 23 | L = loser.input_weights{i}(:); 24 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 25 | L(pos) = W(pos); 26 | loser.input_weights{i} = reshape(L,size(loser.input_weights{i})); 27 | 28 | % electrode_type 29 | W= winner.electrode_type(i,:); 30 | L = loser.electrode_type(i,:); 31 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 32 | L(pos) = W(pos); 33 | loser.electrode_type(i,:) = reshape(L,size(loser.electrode_type(i,:))); 34 | 35 | % config voltage 36 | W= winner.config_voltage(i,:); 37 | L = loser.config_voltage(i,:); 38 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 39 | L(pos) = W(pos); 40 | loser.config_voltage(i,:) = reshape(L,size(loser.config_voltage(i,:))); 41 | 42 | end 43 | 44 | % for output weights 45 | if config.evolve_output_weights 46 | W= winner.output_weights(:); 47 | L = loser.output_weights(:); 48 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 49 | L(pos) = W(pos); 50 | loser.output_weights = reshape(L,size(loser.output_weights)); 51 | end 52 | -------------------------------------------------------------------------------- /Support files/reservoir-type/Multi-reservoir/Ensemble Res/collectEnsembleStates.m: -------------------------------------------------------------------------------- 1 | function[final_states,individual] = collectEnsembleStates(individual,input_sequence,config,target_output) 2 | 3 | %if single input entry, add previous state 4 | if size(input_sequence,1) == 1 5 | input_sequence = [zeros(size(input_sequence)); input_sequence]; 6 | end 7 | 8 | for i= 1:config.num_reservoirs 9 | if size(input_sequence,1) == 2 10 | states{i} = individual.last_state{i}; 11 | else 12 | states{i} = zeros(size(input_sequence,1),individual.nodes(i)); 13 | end 14 | x{i} = zeros(size(input_sequence,1),individual.nodes(i)); 15 | end 16 | 17 | % preassign activation function calls 18 | if size(individual.activ_Fcn,2) > 1 19 | for i= 1:config.num_reservoirs 20 | for p = 1:length(config.activ_list) 21 | index{i,p} = findActiv({individual.activ_Fcn{i,:}},config.activ_list{p}); 22 | end 23 | end 24 | end 25 | 26 | %equation: x{i}(n) = f(Win*u(n) + W_ii*x{i}(n-1)), 27 | for n = 2:size(input_sequence,1) 28 | 29 | for i= 1:config.num_reservoirs 30 | 31 | x{i}(n,:) = x{i}(n,:) + ((individual.W{i,i}*individual.W_scaling(i,i))*states{i}(n-1,:)')'; 32 | 33 | if size(individual.activ_Fcn,2) > 1 34 | for p = 1:length(config.activ_list) 35 | states{i}(n,index{i,p}) = config.activ_list{p}(((individual.input_weights{i}(index{i,p},:)*individual.input_scaling(i))*([individual.bias_node input_sequence(n,:)])')+ x{i}(n,index{i,p})'); 36 | end 37 | else 38 | states{i}(n,:) = individual.activ_Fcn{1}(((individual.input_weights{i}*individual.input_scaling(i))* ([individual.bias_node input_sequence(n,:)])') + x{i}(n,:)'); 39 | end 40 | 41 | end 42 | 43 | end 44 | 45 | 46 | if config.leak_on 47 | states = getLeakStates(states,individual,input_sequence,config); 48 | end 49 | 50 | % concat all states for output weights 51 | final_states = []; 52 | for i= 1:config.num_reservoirs 53 | final_states = [final_states states{i}]; 54 | 55 | %assign last state variable 56 | individual.last_state{i} = states{i}(end,:); 57 | end 58 | 59 | if config.add_input_states == 1 60 | final_states = [final_states input_sequence]; 61 | end 62 | 63 | if size(input_sequence,1) == 2 64 | final_states = final_states(end,:); % remove washout 65 | else 66 | final_states = final_states(config.wash_out+1:end,:); % remove washout 67 | end -------------------------------------------------------------------------------- /Support files/reservoir-type/Multi-reservoir/RoR architecture/generate_internal_weights.m: -------------------------------------------------------------------------------- 1 | function internalWeights = generate_internal_weights(nInternalUnits, ... 2 | connectivity) 3 | % GENERATE_INTERNAL_WEIGHTS creates a random reservoir for an ESN 4 | % 5 | % inputs: 6 | % nInternalUnits = the number of internal units in the ESN 7 | % connectivity \in [0,1], says how many weights should be non-zero 8 | % 9 | % output: 10 | % internalWeights = matrix of size nInternalUnits x nInternalUnits 11 | % internalWeights(i,j) = value of weight(synapse) from unit i to unit j 12 | % internalWeights(i,j) might be different from internalWeights(j,i) 13 | 14 | % 15 | % Created April 30, 2006, D. Popovici 16 | % Copyright: Fraunhofer IAIS 2006 / Patent pending 17 | % Revision 1, Feb 23, 2007, H. Jaeger 18 | % Revision 2, March 10, 2007, H. Jaeger (replaced eigs by myeigs) 19 | % Revision 3, May 10, 2014, H. Jaeger (replaced myeigs again by eigs) 20 | if nInternalUnits ~= 0 21 | success = 0 ; 22 | while success == 0 23 | % following block might fail, thus we repeat until we obtain a valid 24 | % internalWeights matrix 25 | try, 26 | if isinf(connectivity) || isnan(connectivity)|| connectivity > 1 || connectivity == 0 27 | connectivity = 1; 28 | end 29 | internalWeights = sprand(nInternalUnits, nInternalUnits, connectivity); 30 | internalWeights(internalWeights ~= 0) = ... 31 | internalWeights(internalWeights ~= 0) - 0.5; 32 | opts.disp = 0; 33 | maxVal = max(abs(eigs(internalWeights,1, 'lm', opts))); 34 | internalWeights = internalWeights/maxVal; 35 | if sum(isnan(internalWeights)) < 1 36 | success = 1 ; 37 | end 38 | catch, 39 | success = 0 ; 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /Support files/reservoir-type/_Template Reservoir/_recomb_ReservoirName_.m: -------------------------------------------------------------------------------- 1 | %% recomb_ReservoirName_.m 2 | % Template function to recombine/infect an individual to create the new offspring reservoir. Use this as a guide when 3 | % creating a new reservoir. 4 | % 5 | % How this function looks at the end depends on the reservoir. However, 6 | % everything below is typically needed to work with all master scripts. 7 | % 8 | % This is called by the @config.recombFcn pointer. 9 | 10 | function loser = recomb_ReservoirName_(winner,loser,config) 11 | 12 | % params - input_scaling, leak_rate, 13 | W= winner.input_scaling(:); 14 | L = loser.input_scaling(:); 15 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 16 | L(pos) = W(pos); 17 | loser.input_scaling = reshape(L,size(loser.input_scaling)); 18 | 19 | W= winner.leak_rate(:); 20 | L = loser.leak_rate(:); 21 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 22 | L(pos) = W(pos); 23 | loser.leak_rate = reshape(L,size(loser.leak_rate)); 24 | 25 | % Template: recombine other parameters 26 | % W= winner.parameter(:); 27 | % L = loser.parameter(:); 28 | % pos = randperm(length(L),ceil(config.rec_rate*length(L))); 29 | % L(pos) = W(pos); 30 | % loser.parameter = reshape(L,size(loser.parameter)); 31 | 32 | % cycle through sub-reservoirs 33 | for i = 1:config.num_reservoirs 34 | 35 | % input weights 36 | W= winner.input_weights{i}(:); 37 | L = loser.input_weights{i}(:); 38 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 39 | L(pos) = W(pos); 40 | loser.input_weights{i} = reshape(L,size(loser.input_weights{i})); 41 | 42 | 43 | % add additional sub-reservoir specific changes 44 | % e.g., inner weights 45 | % for j = 1:config.num_reservoirs 46 | % W= winner.W{i,j}(:); 47 | % L = loser.W{i,j}(:); 48 | % pos = randperm(length(L),ceil(config.rec_rate*length(L))); 49 | % L(pos) = W(pos); 50 | % loser.W{i,j} = reshape(L,size(loser.W{i,j})); 51 | % end 52 | 53 | end 54 | 55 | % for output weights 56 | if config.evolve_output_weights 57 | W= winner.output_weights(:); 58 | L = loser.output_weights(:); 59 | pos = randperm(length(L),ceil(config.rec_rate*length(L))); 60 | L(pos) = W(pos); 61 | loser.output_weights = reshape(L,size(loser.output_weights)); 62 | end 63 | --------------------------------------------------------------------------------