forked from accord-net/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GC-82: Serializable annotation is needed on class Accord.Statistics.A…
…nalysis.ContrastFunctions.Logcosh
- Loading branch information
1 parent
7b48ebe
commit d9c7d0f
Showing
7 changed files
with
390 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
Sources/Accord.Statistics/Analysis/Contrast Functions/Exponential.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Accord Statistics Library | ||
// The Accord.NET Framework | ||
// http://accord-framework.net | ||
// | ||
// Copyright © César Souza, 2009-2013 | ||
// cesarsouza at gmail.com | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
namespace Accord.Statistics.Analysis.ContrastFunctions | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Exponential contrast function. | ||
/// </summary> | ||
/// | ||
/// <remarks> | ||
/// According to Hyvärinen, the Exponential contrast function may be | ||
/// used when the independent components are highly super-Gaussian or | ||
/// when robustness is very important. | ||
/// </remarks> | ||
/// | ||
/// <seealso cref="IndependentComponentAnalysis"/> | ||
/// | ||
[Serializable] | ||
public class Exponential : IContrastFunction | ||
{ | ||
double alpha = 1; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Exponential"/> class. | ||
/// </summary> | ||
/// <param name="alpha">The exponential alpha constant. Default is 1.</param> | ||
/// | ||
public Exponential(double alpha) | ||
{ | ||
this.alpha = alpha; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the exponential alpha constant. | ||
/// </summary> | ||
/// | ||
public double Alpha { get { return alpha; } } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Exponential"/> class. | ||
/// </summary> | ||
/// | ||
public Exponential() { } | ||
|
||
/// <summary> | ||
/// Contrast function. | ||
/// </summary> | ||
/// | ||
/// <param name="x">The vector of observations.</param> | ||
/// <param name="output">At method's return, this parameter | ||
/// should contain the evaluation of function over the vector | ||
/// of observations <paramref name="x"/>.</param> | ||
/// <param name="derivative">At method's return, this parameter | ||
/// should contain the evaluation of function derivative over | ||
/// the vector of observations <paramref name="x"/>.</param> | ||
/// | ||
public void Evaluate(double[] x, double[] output, double[] derivative) | ||
{ | ||
// Exponential contrast function and its derivative, as given | ||
// in original Hyvärinen's paper. See main references for the | ||
// Independent Component Analysis class for details. | ||
|
||
for (int j = 0; j < x.Length; j++) | ||
{ | ||
double w = x[j]; | ||
double e = System.Math.Exp(-alpha * (w * w) / 2.0); | ||
|
||
// g(w*x) = wx * exp(-(wx^2)/2) | ||
output[j] = w * e; | ||
|
||
// g'(w*x) = (1 - wx^2) * exp(-(wx^2)/2) | ||
derivative[j] = (1.0 - alpha * w * w) * e; | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
54 changes: 54 additions & 0 deletions
54
Sources/Accord.Statistics/Analysis/Contrast Functions/IContrastFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Accord Statistics Library | ||
// The Accord.NET Framework | ||
// http://accord-framework.net | ||
// | ||
// Copyright © César Souza, 2009-2013 | ||
// cesarsouza at gmail.com | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
namespace Accord.Statistics.Analysis.ContrastFunctions | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Common interface for contrast functions. | ||
/// </summary> | ||
/// | ||
/// <remarks> | ||
/// Contrast functions are used as objective functions in | ||
/// neg-entropy calculations. | ||
/// </remarks> | ||
/// | ||
/// <seealso cref="IndependentComponentAnalysis"/> | ||
/// | ||
public interface IContrastFunction | ||
{ | ||
/// <summary> | ||
/// Contrast function. | ||
/// </summary> | ||
/// | ||
/// <param name="x">The vector of observations.</param> | ||
/// <param name="output">At method's return, this parameter | ||
/// should contain the evaluation of function over the vector | ||
/// of observations <paramref name="x"/>.</param> | ||
/// <param name="derivative">At method's return, this parameter | ||
/// should contain the evaluation of function derivative over | ||
/// the vector of observations <paramref name="x"/>.</param> | ||
/// | ||
void Evaluate(double[] x, double[] output, double[] derivative); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Sources/Accord.Statistics/Analysis/Contrast Functions/Kurtosis.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Accord Statistics Library | ||
// The Accord.NET Framework | ||
// http://accord-framework.net | ||
// | ||
// Copyright © César Souza, 2009-2013 | ||
// cesarsouza at gmail.com | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
namespace Accord.Statistics.Analysis.ContrastFunctions | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Kurtosis contrast function. | ||
/// </summary> | ||
/// <remarks> | ||
/// According to using to Hyvärinen, the kurtosis contrast function is | ||
/// justified on statistical grounds only for estimating sub-Gaussian | ||
/// independent components when there are no outliers. | ||
/// </remarks> | ||
/// | ||
/// <seealso cref="IndependentComponentAnalysis"/> | ||
/// | ||
[Serializable] | ||
public class Kurtosis : IContrastFunction | ||
{ | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Kurtosis"/> class. | ||
/// </summary> | ||
/// | ||
public Kurtosis() { } | ||
|
||
/// <summary> | ||
/// Contrast function. | ||
/// </summary> | ||
/// | ||
/// <param name="x">The vector of observations.</param> | ||
/// <param name="output">At method's return, this parameter | ||
/// should contain the evaluation of function over the vector | ||
/// of observations <paramref name="x"/>.</param> | ||
/// <param name="derivative">At method's return, this parameter | ||
/// should contain the evaluation of function derivative over | ||
/// the vector of observations <paramref name="x"/>.</param> | ||
/// | ||
public void Evaluate(double[] x, double[] output, double[] derivative) | ||
{ | ||
for (int j = 0; j < x.Length; j++) | ||
{ | ||
// Kurtosis contrast function and its derivative, as given | ||
// in original Hyvärinen's paper. See main references for the | ||
// Independent Component Analysis class for details. | ||
|
||
double v = x[j]; | ||
|
||
// g(w*x) | ||
output[j] = v * v * v; | ||
|
||
// g'(w*x) | ||
derivative[j] = (1.0 / 3.0) * v * v; | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
Sources/Accord.Statistics/Analysis/Contrast Functions/Logcosh.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Accord Statistics Library | ||
// The Accord.NET Framework | ||
// http://accord-framework.net | ||
// | ||
// Copyright © César Souza, 2009-2013 | ||
// cesarsouza at gmail.com | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
namespace Accord.Statistics.Analysis.ContrastFunctions | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Log-cosh (Hyperbolic Tangent) contrast function. | ||
/// </summary> | ||
/// | ||
/// <remarks> | ||
/// According to Hyvärinen, the Logcosh contrast function | ||
/// is a good general-purpose contrast function. | ||
/// </remarks> | ||
/// | ||
/// <seealso cref="IndependentComponentAnalysis"/> | ||
/// | ||
[Serializable] | ||
public class Logcosh : IContrastFunction | ||
{ | ||
double alpha = 1; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Logcosh"/> class. | ||
/// </summary> | ||
/// | ||
public Logcosh() { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Logcosh"/> class. | ||
/// </summary> | ||
/// | ||
/// <param name="alpha">The log-cosh alpha constant. Default is 1.</param> | ||
/// | ||
public Logcosh(double alpha) | ||
{ | ||
this.alpha = alpha; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the exponential log-cosh constant. | ||
/// </summary> | ||
/// | ||
public double Alpha { get { return alpha; } } | ||
|
||
/// <summary> | ||
/// Contrast function. | ||
/// </summary> | ||
/// | ||
/// <param name="x">The vector of observations.</param> | ||
/// <param name="output">At method's return, this parameter | ||
/// should contain the evaluation of function over the vector | ||
/// of observations <paramref name="x"/>.</param> | ||
/// <param name="derivative">At method's return, this parameter | ||
/// should contain the evaluation of function derivative over | ||
/// the vector of observations <paramref name="x"/>.</param> | ||
/// | ||
public void Evaluate(double[] x, double[] output, double[] derivative) | ||
{ | ||
// Log-cosh contrast function and its derivative, as given | ||
// in original Hyvärinen's paper. See main references for the | ||
// Independent Component Analysis class for details. | ||
|
||
for (int j = 0; j < x.Length; j++) | ||
{ | ||
double f; | ||
|
||
// g(w*x) | ||
f = output[j] = System.Math.Tanh(alpha * x[j]); | ||
|
||
// g'(w*x) | ||
derivative[j] = alpha * (1.0 - f * f); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.