liboutputfunctions.cpp
1 /********************************************************************************
2  * Neural Network Framework. *
3  * Copyright (C) 2005-2009 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #include "liboutputfunctions.h"
21 #include "cluster.h"
22 #include <QStringList>
23 #include <QRegExp>
24 #include <cmath>
25 
26 using namespace Eigen;
27 
28 namespace farsa {
29 
30 IdentityFunction::IdentityFunction()
31  : OutputFunction() {
32 }
33 
34 void IdentityFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
35  outputs = inputs;
36 }
37 
38 bool IdentityFunction::derivate( const DoubleVector&, const DoubleVector&, DoubleVector& derivates ) const {
39  derivates.setConstant( 1.0 );
40  return true;
41 }
42 
44 {
45  ((void)params);
46  ((void)prefix);
47  // Nothing to configure
48 }
49 
50 void IdentityFunction::save(ConfigurationParameters& params, QString prefix)
51 {
52  // Just telling our type to ConfigurationParameters
53  params.startObjectParameters(prefix, "IdentityFunction", this);
54 }
55 
57  : OutputFunction() {
58  this->rate = rate;
59 }
60 
61 void ScaleFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
62  outputs = inputs * rate;
63 }
64 
65 bool ScaleFunction::derivate( const DoubleVector&, const DoubleVector&, DoubleVector& derivates ) const {
66  derivates.setConstant( rate );
67  return true;
68 }
69 
71 {
72  rate = 1.0;
73  QString str = params.getValue(prefix + "rate");
74  if (!str.isEmpty()) {
75  bool ok;
76  rate = str.toDouble(&ok);
77  if (!ok) {
78  rate = 1.0;
79  }
80  }
81 }
82 
83 void ScaleFunction::save(ConfigurationParameters& params, QString prefix)
84 {
85  params.startObjectParameters(prefix, "ScaleFunction", this);
86  params.createParameter(prefix, "rate", QString::number(rate));
87 }
88 
90  : OutputFunction() {
91  gainv = gain;
92 }
93 
94 void GainFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
95  for( int i=0; i<inputs.size(); i++ ) {
96  outputs[i] = inputs[i] + gainv;
97  }
98 }
99 
100 bool GainFunction::derivate( const DoubleVector&, const DoubleVector&, DoubleVector& derivates ) const {
101  derivates.setConstant( 1.0 );
102  return true;
103 }
104 
106 {
107  gainv = 1.0;
108  QString str = params.getValue(prefix + "gain");
109  if (!str.isEmpty()) {
110  bool ok;
111  gainv = str.toDouble(&ok);
112  if (!ok) {
113  gainv = 1.0;
114  }
115  }
116 }
117 
118 void GainFunction::save(ConfigurationParameters& params, QString prefix)
119 {
120  params.startObjectParameters(prefix, "GainFunction", this);
121  params.createParameter(prefix, "gain", QString::number(gainv));
122 }
123 
125  lambda = l;
126 }
127 
128 void SigmoidFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
129  // ____________1_________________
130  // exp( -lamba*inputs ) + 1
131  for( int i=0; i<inputs.size(); i++ ) {
132  outputs[i] = 1.0/(exp(-lambda*inputs[i])+1.0);
133  }
134 }
135 
136 bool SigmoidFunction::derivate( const DoubleVector&, const DoubleVector& outputs, DoubleVector& derivates ) const {
137  // derivates <- lambda * out * (1.0-out)
138  for( int i=0; i<outputs.size(); i++ ) {
139  derivates[i] = lambda * outputs[i] * (1.0-outputs[i]);
140  }
141  return true;
142 }
143 
145 {
146  lambda = 1.0;
147  QString str = params.getValue(prefix + "lambda");
148  if (!str.isEmpty()) {
149  bool ok;
150  lambda = str.toDouble(&ok);
151  if (!ok) {
152  lambda = 1.0;
153  }
154  }
155 }
156 
157 void SigmoidFunction::save(ConfigurationParameters& params, QString prefix)
158 {
159  params.startObjectParameters(prefix, "SigmoidFunction", this);
160  params.createParameter(prefix, "lambda", QString::number(lambda));
161 }
162 
164  : OutputFunction() {
165  lambda = l;
166 }
167 
168 void FakeSigmoidFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
169  unsigned int size = inputs.size();
170  double x;
171  double x0 = 6. + 2./3.;
172  double zero = 0.5;
173  for ( unsigned int i = 0; i<size; i++ ) {
174  x = inputs[i];
175  x *= lambda;
176  x -= (.5 - zero) / (.075 + zero);
177  if ( x <= -x0 ) {
178  outputs[i] = 0.0;
179  } else {
180  if ( x < x0 ) {
181  outputs[i] = .5 + .575 * x / ( 1.0 + fabs(x) );
182  } else {
183  outputs[i] = 1.0;
184  }
185  }
186  }
187 }
188 
189 bool FakeSigmoidFunction::derivate( const DoubleVector&, const DoubleVector& outputs, DoubleVector& derivates ) const {
190  // derivates <- lambda * out * (1.0-out)
191  for( int i=0; i<outputs.size(); i++ ) {
192  derivates[i] = lambda * outputs[i] * (1.0-outputs[i]);
193  }
194  return true;
195 }
196 
198 {
199  lambda = 1.0;
200  QString str = params.getValue(prefix + "lambda");
201  if (!str.isEmpty()) {
202  bool ok;
203  lambda = str.toDouble(&ok);
204  if (!ok) {
205  lambda = 1.0;
206  }
207  }
208 }
209 
211 {
212  params.startObjectParameters(prefix, "FakeSigmoidFunction", this);
213  params.createParameter(prefix, "lambda", QString::number(lambda));
214 }
215 
217  : OutputFunction() {
218  lambda = l;
219  this->min = min;
220  this->max = max;
221 }
222 
223 void ScaledSigmoidFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
224  //--- compute the sigmoid
225  // ____________1_________________
226  // exp( -lamba*inputs ) + 1
227  for( int i=0; i<inputs.size(); i++ ) {
228  outputs[i] = 1.0/(exp(-lambda*inputs[i])+1.0);
229  //--- and scale it
230  outputs[i] = (max-min)*outputs[i]+min;
231  }
232 }
233 
234 bool ScaledSigmoidFunction::derivate( const DoubleVector&, const DoubleVector& outputs, DoubleVector& derivates ) const {
235  // derivates <- lambda * out * (1.0-out)
236  for( int i=0; i<outputs.size(); i++ ) {
237  derivates[i] = lambda * outputs[i] * (1.0-outputs[i]);
238  }
239  return true;
240 }
241 
243 {
244  lambda = 1.0;
245  QString str = params.getValue(prefix + "lambda");
246  if (!str.isEmpty()) {
247  bool ok;
248  lambda = str.toDouble(&ok);
249  if (!ok) {
250  lambda = 1.0;
251  }
252  }
253 
254  min = -1.0;
255  str = params.getValue(prefix + "min");
256  if (!str.isEmpty()) {
257  bool ok;
258  min = str.toDouble(&ok);
259  if (!ok) {
260  min = -1.0;
261  }
262  }
263 
264  max = 1.0;
265  str = params.getValue(prefix + "max");
266  if (!str.isEmpty()) {
267  bool ok;
268  max = str.toDouble(&ok);
269  if (!ok) {
270  max = 1.0;
271  }
272  }
273 }
274 
276 {
277  params.startObjectParameters(prefix, "ScaledSigmoidFunction", this);
278  params.createParameter(prefix, "lambda", QString::number(lambda));
279  params.createParameter(prefix, "min", QString::number(min));
280  params.createParameter(prefix, "max", QString::number(max));
281 }
282 
284  : OutputFunction() {
285  min_x = 0.0;
286  max_x = 0.0;
287  min_y = 0.0;
288  max_y = 0.0;
289 }
290 
291 RampFunction::RampFunction( double minX, double maxX, double minY, double maxY )
292  : OutputFunction() {
293  min_x = minX;
294  max_x = maxX;
295  min_y = minY;
296  max_y = maxY;
297 }
298 
299 void RampFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
300  unsigned int size = inputs.size();
301  double m = ( max_y-min_y )/( max_x-min_x );
302  double q = min_y - m*min_x;
303  for ( unsigned int i = 0; i<size; i++ ) {
304  double ret = m*(inputs[i]) + q;
305  if (ret < min_y) {
306  outputs[i] = min_y;
307  } else if (ret > max_y) {
308  outputs[i] = max_y;
309  } else {
310  outputs[i] = ret;
311  }
312  }
313 }
314 
315 bool RampFunction::derivate( const DoubleVector& inputs, const DoubleVector&, DoubleVector& derivates ) const {
316  for( int i=0; i<inputs.size(); i++ ) {
317  if ( inputs[i] >= min_x && inputs[i] <= max_x ) {
318  derivates[i] = ( max_y-min_y )/( max_x-min_x );
319  } else {
320  double y;
321  y = 1.0/( 1.0 + std::exp( -inputs[i] ) );
322  derivates[i] = y * ( 1.0 - y );
323  }
324  }
325  return true;
326 }
327 
329 {
330  min_x = 0.0;
331  QString str = params.getValue(prefix + "minX");
332  if (!str.isEmpty()) {
333  bool ok;
334  min_x = str.toDouble(&ok);
335  if (!ok) {
336  min_x = 0.0;
337  }
338  }
339 
340  max_x = 0.0;
341  str = params.getValue(prefix + "maxX");
342  if (!str.isEmpty()) {
343  bool ok;
344  max_x = str.toDouble(&ok);
345  if (!ok) {
346  max_x = 0.0;
347  }
348  }
349 
350  min_y = 0.0;
351  str = params.getValue(prefix + "minY");
352  if (!str.isEmpty()) {
353  bool ok;
354  min_y = str.toDouble(&ok);
355  if (!ok) {
356  min_y = 0.0;
357  }
358  }
359 
360  max_y = 0.0;
361  str = params.getValue(prefix + "maxY");
362  if (!str.isEmpty()) {
363  bool ok;
364  max_y = str.toDouble(&ok);
365  if (!ok) {
366  max_y = 0.0;
367  }
368  }
369 }
370 
371 void RampFunction::save(ConfigurationParameters& params, QString prefix)
372 {
373  params.startObjectParameters(prefix, "RampFunction", this);
374  params.createParameter(prefix, "minX", QString::number(min_x));
375  params.createParameter(prefix, "maxX", QString::number(max_x));
376  params.createParameter(prefix, "minY", QString::number(min_y));
377  params.createParameter(prefix, "maxY", QString::number(max_y));
378 }
379 
381  : OutputFunction() {
382  m = 0.0;
383  b = 0.0;
384 }
385 
386 LinearFunction::LinearFunction( double m, double b )
387  : OutputFunction() {
388  this->m = m;
389  this->b = b;
390 }
391 
392 void LinearFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
393  for( int i=0; i<inputs.size(); i++ ) {
394  outputs[i] = m*inputs[i]+b;
395  }
396 }
397 
398 bool LinearFunction::derivate( const DoubleVector& , const DoubleVector&, DoubleVector& derivates ) const {
399  derivates.setConstant( m );
400  return true;
401 }
402 
404 {
405  m = 0.0;
406  QString str = params.getValue(prefix + "m");
407  if (!str.isEmpty()) {
408  bool ok;
409  m = str.toDouble(&ok);
410  if (!ok) {
411  m = 0.0;
412  }
413  }
414 
415  b = 0.0;
416  str = params.getValue(prefix + "b");
417  if (!str.isEmpty()) {
418  bool ok;
419  b = str.toDouble(&ok);
420  if (!ok) {
421  b = 0.0;
422  }
423  }
424 }
425 
426 void LinearFunction::save(ConfigurationParameters& params, QString prefix)
427 {
428  params.startObjectParameters(prefix, "LinearFunction", this);
429  params.createParameter(prefix, "m", QString::number(m));
430  params.createParameter(prefix, "b", QString::number(b));
431 }
432 
433 StepFunction::StepFunction( double min, double max, double threshold )
434  : OutputFunction() {
435  this->min = min;
436  this->max = max;
437  this->threshold = threshold;
438 }
439 
440 void StepFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
441  for( int i = 0; i<inputs.size(); i++ ) {
442  ( inputs[i] > threshold ) ? outputs[i] = max : outputs[i] = min;
443  }
444 }
445 
446 bool StepFunction::derivate( const DoubleVector& inputs, const DoubleVector&, DoubleVector& derivates ) const {
447  //--- return the same as if it is a sigmoid with lambda = 1
448  for( int i=0; i<inputs.size(); i++ ) {
449  double y;
450  y = 1.0/( 1.0 + std::exp( -inputs[i] ) );
451  derivates[i] = y * ( 1.0 - y );
452  }
453  return true;
454 }
455 
457 {
458  min = 0.0;
459  QString str = params.getValue(prefix + "min");
460  if (!str.isEmpty()) {
461  bool ok;
462  min = str.toDouble(&ok);
463  if (!ok) {
464  min = 0.0;
465  }
466  }
467 
468  max = 1.0;
469  str = params.getValue(prefix + "max");
470  if (!str.isEmpty()) {
471  bool ok;
472  max = str.toDouble(&ok);
473  if (!ok) {
474  max = 1.0;
475  }
476  }
477 
478  threshold = 0.0;
479  str = params.getValue(prefix + "threshold");
480  if (!str.isEmpty()) {
481  bool ok;
482  threshold = str.toDouble(&ok);
483  if (!ok) {
484  threshold = 0.0;
485  }
486  }
487 }
488 
489 void StepFunction::save(ConfigurationParameters& params, QString prefix)
490 {
491  params.startObjectParameters(prefix, "StepFunction", this);
492  params.createParameter(prefix, "min", QString::number(min));
493  params.createParameter(prefix, "max", QString::number(max));
494  params.createParameter(prefix, "threshold", QString::number(threshold));
495 }
496 
498  : OutputFunction(), delta(), outprev()
499 {
500 }
501 
503  : OutputFunction(), delta(d), outprev(VectorXd::Zero(d.size())) {
504 }
505 
506 void LeakyIntegratorFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
507  //--- y <- delta*y(t-1) + (1.0-delta)*inputs
508  for( int i=0; i<inputs.size(); i++ ) {
509  outputs[i] = delta[i]*outprev[i] + (1.0-delta[i])*inputs[i];
510  }
511  outprev = outputs;
512 }
513 
515  outprev.setZero();
516 }
517 
519  if ( clusterv->numNeurons() != delta.size() ) {
520  delta.resize( clusterv->numNeurons() );
521  outprev.resize( clusterv->numNeurons() );
522  }
523 }
524 
526 {
527  // Delta is a vector, that is a list of space-separated values
528  QString str = params.getValue(prefix + "delta");
529  if (!str.isEmpty()) {
530  QStringList list = str.split(QRegExp("\\s+"), QString::SkipEmptyParts);
531  delta.resize(list.size());
532  for( int i = 0; i < list.size(); i++) {
533  bool ok;
534  delta[i] = list[i].toDouble(&ok);
535  if (!ok) {
536  delta[i] = 0.0;
537  }
538  }
539  }
540 
541  // Also reloading outprev (resizing it to match delta length)
542  str = params.getValue(prefix + "outprev");
543  if (!str.isEmpty()) {
544  QStringList list = str.split(QRegExp("\\s+"), QString::SkipEmptyParts);
545  outprev.resize(list.size());
546  for( int i = 0; i < list.size(); i++) {
547  bool ok;
548  outprev[i] = list[i].toDouble(&ok);
549  if (!ok) {
550  outprev[i] = 0.0;
551  }
552  }
553  }
554  outprev.resize(delta.size());
555 }
556 
558 {
559  params.startObjectParameters(prefix, "LeakyIntegratorFunction", this);
560 
561  // First creating a string list, then transforming to a single string
562  QStringList list;
563  for (int i = 0; i < delta.size(); i++) {
564  list.push_back(QString::number(delta[i]));
565  }
566  params.createParameter(prefix, "delta", list.join(" "));
567 
568  // Saving in the same way also outprev
569  list.clear();
570  for (int i = 0; i < delta.size(); i++) {
571  list.push_back(QString::number(outprev[i]));
572  }
573  params.createParameter(prefix, "outprev", list.join(" "));
574 }
575 
576 LogLikeFunction::LogLikeFunction( double A, double B )
577  : OutputFunction() {
578  this->A = A;
579  this->B = B;
580 }
581 
582 void LogLikeFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
583  //--- y <- x / ( 1+A*x+b )
584  for( int i=0; i<inputs.size(); i++ ) {
585  outputs[i] = inputs[i]/(1.0+A*inputs[i]+B);
586  }
587 }
588 
590 {
591  A = 1.0;
592  QString str = params.getValue(prefix + "A");
593  if (!str.isEmpty()) {
594  bool ok;
595  A = str.toDouble(&ok);
596  if (!ok) {
597  A = 1.0;
598  }
599  }
600 
601  B = 5.0;
602  str = params.getValue(prefix + "B");
603  if (!str.isEmpty()) {
604  bool ok;
605  B = str.toDouble(&ok);
606  if (!ok) {
607  B = 5.0;
608  }
609  }
610 }
611 
612 void LogLikeFunction::save(ConfigurationParameters& params, QString prefix)
613 {
614  params.startObjectParameters(prefix, "LogLikeFunction", this);
615  params.createParameter(prefix, "A", QString::number(A));
616  params.createParameter(prefix, "B", QString::number(B));
617 }
618 
620  : OutputFunction(), first(), second(), mid() {
621 }
622 
624  : OutputFunction(), first(f), second(g), mid() {
625 }
626 
628  // auto_ptr will release memory for us
629 }
630 
631 void CompositeFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
632  first->apply( inputs, mid );
633  second->apply( mid, outputs );
634 }
635 
637  first.reset(f);
638  first->setCluster( clusterv );
639  return true;
640 }
641 
643  return first.get();
644 }
645 
647  second.reset(g);
648  second->setCluster( clusterv );
649  return true;
650 }
651 
653  return second.get();
654 }
655 
657  mid.resize( clusterv->numNeurons() );
658  first->setCluster( clusterv );
659  second->setCluster( clusterv );
660 }
661 
663 {
664  // We don't need configured component functions here (and they will be
665  // configured after exiting from this function)
666  first.reset(params.getObjectFromGroup<OutputFunction>(prefix + "First"));
667  second.reset(params.getObjectFromGroup<OutputFunction>(prefix + "Second"));
668 
669  // We don't need to reload a reference to the cluster as he calls our setCluster
670  // function after our creation
671 }
672 
674 {
675  params.startObjectParameters(prefix, "CompositeFunction", this);
676  params.createParameter(prefix, "first", first.get());
677  params.createParameter(prefix, "second", second.get());
678 
679  // We don't need to save the reference to the cluster as he calls our setCluster
680  // function after our creation
681 }
682 
684  : OutputFunction(), first(), second(), mid()
685 {
686  this->w1 = 0.0;
687  this->w2 = 0.0;
688 }
689 
691  : OutputFunction(), first(f), second(g), mid() {
692  this->w1 = w1;
693  this->w2 = w2;
694 }
695 
697  // auto_ptr will release memory for us
698 }
699 
700 void LinearComboFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
701  first->apply( inputs, mid );
702  mid *= w1;
703  second->apply( inputs, outputs );
704  outputs *= w2;
705  outputs += mid;
706 }
707 
709  first.reset(f);
710  first->setCluster( clusterv );
711  return true;
712 }
713 
715  return first.get();
716 }
717 
719  w1 = v;
720  return true;
721 }
722 
724  return w1;
725 }
726 
728  second.reset(g);
729  second->setCluster( clusterv );
730  return true;
731 }
732 
734  return second.get();
735 }
736 
738  w2 = v;
739  return true;
740 }
741 
743  return w2;
744 }
745 
747  mid.resize( clusterv->numNeurons() );
748  first->setCluster( clusterv );
749  second->setCluster( clusterv );
750 }
751 
753 {
754  // We don't need configured component functions here (and they will be
755  // configured after exiting from this function)
756  first.reset(params.getObjectFromGroup<OutputFunction>(prefix + "First"));
757 
758  w1 = 0.0;
759  QString str = params.getValue(prefix + "w1");
760  if (!str.isEmpty()) {
761  bool ok;
762  w1 = str.toDouble(&ok);
763  if (!ok) {
764  w1 = 0.0;
765  }
766  }
767 
768  second.reset(params.getObjectFromGroup<OutputFunction>(prefix + "Second"));
769 
770  w2 = 0.0;
771  str = params.getValue(prefix + "w2");
772  if (!str.isEmpty()) {
773  bool ok;
774  w2 = str.toDouble(&ok);
775  if (!ok) {
776  w2 = 0.0;
777  }
778  }
779 
780  // We don't need to reload a reference to the cluster as he calls our setCluster
781  // function after our creation
782 }
783 
785 {
786  params.startObjectParameters(prefix, "LinearComboFunction", this);
787  params.createParameter(prefix, "first", first.get());
788  params.createParameter(prefix, "w1", QString::number(w1));
789  params.createParameter(prefix, "second", second.get());
790  params.createParameter(prefix, "w2", QString::number(w2));
791 
792  // We don't need to save the reference to the cluster as he calls our setCluster
793  // function after our creation
794 }
795 
796 }
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
DoubleVector outprev
previous outputs
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method it computes: y <- second( first( input, mid ), outputs ) where mid ...
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
GainFunction(double gain=1.0)
Construct.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return always 1 (an explain of why will be coming soon)
OutputFunction * getSecondFunction()
Return the second function of CompositeFunction.
StepFunction(double min=0.0f, double max=1.0f, double threshold=0.0f)
Construct a step updater.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
OutputFunction Class.
OutputFunction * getFirstFunction()
Return the first function of LinearComboFunction.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method it computes: y(t) <- delta * y(t-1) + (1.0-delta) * inputs...
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
SigmoidFunction(double l=1.0)
Construct a sigmoid updater with parameter l.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
bool setFirstWeight(double v)
Set the first weight of LinearComboFunction.
Library of Common OutputFunction.
bool setFirstFunction(OutputFunction *f)
Set the first function of LinearComboFunction.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
double A
A coefficient.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return always the rate (an explain of why will be coming soon)
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
OutputFunction * getFirstFunction()
Return the first function of CompositeFunction.
double max
max is the y value when x -> +infinite
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the identity function.
virtual void clusterSetted()
resize itself to fit the size of Cluster
Cluster * clusterv
Cluster on which the OutputFunction is inserted.
ScaledSigmoidFunction(double l=1.0, double min=-1.0, double max=+1.0)
Construct a scaled sigmoid updater with parameter l.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return the m coefficient if x is in [minX, maxX] and x(1-x) otherwise
RampFunction()
Default constructor.
double B
B coefficient.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void clusterSetted()
recursive call setCluster on first and second function setted
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return the approximation commonly used in backpropagation learning: x(1-x)
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
OutputFunction * getSecondFunction()
Return the second function of CompositeFunction.
double threshold
Threshold.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return the approximation commonly used in backpropagation learning: y*(1-y)
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method it computes: y <- w1*first(input,output) + w2*second(input,outputs)
DoubleVector delta
delta is the leak rate of the function
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
bool startObjectParameters(QString groupPath, QString typeName, ParameterSettable *object)
void zeroingStatus()
Zeroing the status.
double getFirstWeight()
Return the first weight of LinearComboFunction.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
LeakyIntegratorFunction()
Default constructor.
double min
min is the y value when x -> -infinite
virtual void clusterSetted()
recursive call setCluster on first and second function setted
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the Gain function.
QString getValue(QString path, bool alsoMatchParents=false) const
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the identity function.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return the m coefficient
bool setSecondFunction(OutputFunction *g)
Set the second function of CompositeFunction.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
TypeToCreate * getObjectFromGroup(QString group, bool configure=true, bool forceObjectCreation=false)
virtual ~LinearComboFunction()
Destructor.
LogLikeFunction(double A=1.0, double B=5.0)
Construct a LogLike with deltas specified.
double max
Maximum value.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
double lambda
lambda is the slope of the curve
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
This file contains the declarations of the Cluster class.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return the approximation commonly used in backpropagation learning: x(1-x)
CompositeFunction()
Default constructor.
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
LinearFunction()
Default constructor.
bool setSecondWeight(double v)
Set the second weight of LinearComboFunction.
LinearComboFunction()
Standard constructor.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
ScaleFunction(double rate=1.0)
Construct.
double min
Minimum value.
bool setSecondFunction(OutputFunction *g)
Set the second function of CompositeFunction.
virtual ~CompositeFunction()
Destructor.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
Using the derivate of the sigmoid function!!!
bool setFirstFunction(OutputFunction *f)
Set the first function of CompositeFunction.
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the updating method.
unsigned int numNeurons() const
Return the number of neurons (the length of input and output arrays)
Definition: cluster.h:82
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
double lambda
lambda is the slope of the curve
FakeSigmoidFunction(double l=1.0)
Construct a sigmoid updater with parameter l.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
void createParameter(QString groupPath, QString parameter)
virtual bool derivate(const DoubleVector &x, const DoubleVector &y, DoubleVector &d) const
return always 1 (an explain of why will be coming soon)
double getSecondWeight()
Return the second weight of LinearComboFunction.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
double lambda
lambda is the slope of the curve