summaryrefslogtreecommitdiff
path: root/macros/sigmoid_train.sci
blob: 6f67d4b66759d56018618d83d6f28af81c498e84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function y = sigmoid_train(t, ranges, rc)
// Evaluate a train of sigmoid functions at T.

//Calling Sequence
//y = sigmoid_train(t, ranges, rc)

//Parameters
//t: integer
//ranges: matrix
//rc:timeconstant

//Description
//The number and duration of each sigmoid is determined from RANGES. Each row of RANGES represents a real interval, e.g.  if sigmoid 'i' starts at 't=0.1' and ends at 't=0.5', then 'RANGES(i,:) = [0.1 0.5]'.  The input RC is an array that defines the rising and falling time constants of each sigmoid.  Its size must equal the size of RANGES.

//Examples
//sigmoid_train(0.1,[1:3],4)

//Output :
// ans  =
//
//    0.2737470



funcprot(0);

//**************************************************************************************************
//______________________________________________version1 code (not working)_________________________
//__________________________________________________________________________________________________
//**************************************************************************************************


//rhs=argn(2);
//if (rhs<3 | rhs>3) then
//    error("Wrong number of input arguments");
//end
//
//select(rhs)
//case 3 then
//    y=callOctave("sigmoid_train", t, ranges, rc)
//end


//**************************************************************************************************
//______________________________________________version2 code ( working)____________________________
//__________________________________________________________________________________________________
//**************************************************************************************************

  nRanges = size (ranges, 1);
  if isscalar (rc)

    rc = rc * ones (nRanges,2);

  elseif or( size(rc) ~= [1 1])

    if length(rc) ~= nRanges
      error('signalError','Length of time constant must equal number of ranges.')
    end
    if isrow (rc)
      rc = rc';
    end
    rc = repmat (rc,1,2);

  end


  flag_transposed = %F;
  if iscolumn (t)
    t               = t.';
    flag_transposed = %T;
  end
  [ncol nrow]     = size (t);

  T    = repmat (t, nRanges, 1);
  RC1  = repmat (rc(:,1), 1, nrow);
  RC2  = repmat (rc(:,2), 1, nrow);
  a_up = (repmat (ranges(:,1), 1 ,nrow) - T)./RC1;
  a_dw = (repmat (ranges(:,2), 1 ,nrow) - T)./RC2;


  Y        = 1 ./ ( 1 + exp (a_up) ) .* (1 - 1 ./ ( 1 + exp (a_dw) ) )
  y = max(Y,'r');

  if flag_transposed
    y = y.';
  end

endfunction