Skip to content

Commit

Permalink
many bug fixes and improvemnents to xfit
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-s committed Jul 17, 2019
1 parent 20f1a25 commit 61ba075
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 63 deletions.
6 changes: 3 additions & 3 deletions +xolotl/+examples/burstingCostFcn.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@


% accumulate errors
C = xfit.binCost([950 1050],metrics.burst_period);
C = C + xfit.binCost([.1 .3],metrics.duty_cycle_mean);
C = C + xfit.binCost([7 10],metrics.n_spikes_per_burst_mean);
C = xtools.binCost([950 1050],metrics.burst_period);
C = C + xtools.binCost([.1 .3],metrics.duty_cycle_mean);
C = C + xtools.binCost([7 10],metrics.n_spikes_per_burst_mean);

% safety -- if something goes wrong, return a large cost
if isnan(C)
Expand Down
1 change: 1 addition & 0 deletions +xolotl/testConductances.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
if exist([xroot filesep 'cond_check.mat'],'file') == 2
load([xroot filesep 'cond_check.mat'])
else
warning('It looks like this is the first time conductances are being checked. This will take a while...')
ok_channels = {};
end

Expand Down
46 changes: 46 additions & 0 deletions +xtools/binCost.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
% __ _ _
% __ __/ _(_) |_
% \ \/ / |_| | __|
% > <| _| | |_
% /_/\_\_| |_|\__|
%
%
% ### binCost
%
% **Syntax**
%
% ```matlab
% c = xfit.binCost(allowed_range, actual_value)
% ```
%
% **Description**
%
% A static method that computes a quadratic cost
% when `actual_value` is outside of the minimum and maximum
% set by the 2-vector `allowed_range`, and returns zero otherwise.
%
% This method can be used as part of a simulation function
% when it is important for neurocomputational properties of interest to
% fit within a given range, rather than necessarily fit a value perfectly.

function c = binCost(allowed_range,actual_value)


if isnan(actual_value)
c = 1;
return
end

w = (allowed_range(2) - allowed_range(1))/2;
m = (allowed_range(2) + allowed_range(1))/2;

if actual_value < allowed_range(1)
d = m - actual_value;
c = (1- (w/d));
elseif actual_value > allowed_range(2)
d = actual_value - m;
c = (1- (w/d));
else
% no cost
c = 0;
end
49 changes: 0 additions & 49 deletions @xfit/binCost.m

This file was deleted.

4 changes: 2 additions & 2 deletions @xfit/evaluate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and return a cost (a double).
configured in the xfit object:
- `x` (the xolotl object)
- `sim_func`
- `SimFcn`
- `parameter_names`
%}
Expand All @@ -34,4 +34,4 @@ and return a cost (a double).
for i = 1:length(self.parameter_names)
self.x.set(self.parameter_names{i},params(i))
end
c = self.sim_func(self.x, self.data);
c = self.SimFcn(self.x, self.data);
2 changes: 1 addition & 1 deletion @xfit/fit.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function fit(self)

assert(~isempty(self.parameter_names),'No parameter names defined')
assert(~isempty(self.x),'Xolotl object not configured')
assert(~isempty(self.sim_func),'Simulation function not set')
assert(~isempty(self.SimFcn),'Simulation function not set')

if isempty(self.seed) && ~isempty(self.ub) && ~isempty(self.lb)
% pick a random seed within bounds
Expand Down
15 changes: 10 additions & 5 deletions @xfit/xfit.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,38 @@
x@xolotl

% function to minimize
sim_func@function_handle
SimFcn@function_handle

% parameters to optimize
parameter_names@cell
seed
lb
ub

PlotFcn



display_type = 'iter'
Display = 'iter'
engine

% logging
timestamp


% this can be used to store any user-defined data
data


options

end % end props


properties (SetAccess = private)
best_cost
options


% logging
timestamp
end

methods
Expand Down
11 changes: 8 additions & 3 deletions examples/demo_xfit.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
% we instantiate the xfit object
% and specify the particle swarm engine
p = xfit('particleswarm');
p.options.UseParallel = true;

% we assign a cost function
p.sim_func = @xolotl.examples.burstingCostFcn;
p.SimFcn = @xolotl.examples.burstingCostFcn;


% we assign the xolotl object
p.x = x;
Expand All @@ -34,6 +36,10 @@
plot(time,V,'k')
title('Before optimization')

subplot(2,1,2); hold on
set(gca,'XLim',[0 10],'YLim',[-80 50])


% perform the optimization procedure
p.fit;

Expand All @@ -43,8 +49,7 @@


% visualize the results of the optimization
subplot(2,1,2); hold on
set(gca,'XLim',[0 10],'YLim',[-80 50])

x.t_end = 10e3;
V = x.integrate;
time = (1:length(V))*1e-3*x.dt;
Expand Down

0 comments on commit 61ba075

Please sign in to comment.