- initial version

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@14 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-09-24 17:21:29 +00:00
commit 470437eecb
1107 changed files with 428404 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.10692699">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.10692699" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.10692699" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.10692699." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.2087661599" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.eclipse.cdt.build.core.prefbase.toolchain.2087661599.1142336933" name=""/>
<builder autoBuildTarget="" buildPath="/home/jens/work/RBM/Builds/Linux" command="" enableAutoBuild="false" enableCleanBuild="false" enabledIncrementalBuild="false" id="org.eclipse.cdt.build.core.settings.default.builder.1283324089" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1278010779" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.62358562" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.875592394" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.751305630" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1332004879" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.447702799" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1580487548" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="JuceLibraryCode|modules" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="JuceLibraryCode"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="modules"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="RBM.null.1518814991" name="RBM"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.10692699">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/RBM"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>
+39
View File
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RBM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers></triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>JuceLibraryCode</name>
<type>2</type>
<location>/home/jens/work/RBM/JuceLibraryCode</location>
</link>
<link>
<name>modules</name>
<type>2</type>
<location>/home/jens/JUCE/modules</location>
</link>
</linkedResources>
</projectDescription>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="0.10692699" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" ref="shared-provider"/>
</extension>
</configuration>
</project>
@@ -0,0 +1,67 @@
eclipse.preferences.version=1
org.eclipse.cdt.codan.checkers.errnoreturn=Warning
org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
org.eclipse.cdt.codan.checkers.errreturnvalue=Error
org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.checkers.noreturn=Error
org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false}
org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true}
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error
org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error
org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false}
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false}
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true}
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true}
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")}
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+292
View File
@@ -0,0 +1,292 @@
/*
==============================================================================
Layer.hpp
Created: 21 Sep 2014 1:55:15pm
Author: jens
==============================================================================
*/
#ifndef LAYER_HPP
#define LAYER_HPP
#include "noise.h"
class Weights
{
public:
Weights(uint32_t numVisible, uint32_t numHidden)
: m_ppW(nullptr)
, m_pBiasVisible(nullptr)
, m_pBiasHidden(nullptr)
, m_numVisible(numVisible)
, m_numHidden(numHidden)
{
alloc();
Noise_Init(&m_noise, 0x32727155);
shuffle(0);
}
~Weights()
{
Noise_Free(&m_noise);
free();
}
void shuffle(double stdDev)
{
uint32_t i, j;
double kdev = stdDev*sqrt(12.0);
for (j=0; j < m_numVisible; j++)
{
m_pBiasVisible[j] = kdev*Noise_Uniform(&m_noise, 0.5);
}
for (i=0; i < m_numHidden; i++)
{
m_pBiasHidden[i] = kdev*Noise_Uniform(&m_noise, 0.5);
}
for (i=0; i < m_numHidden; i++)
{
for (j=0; j < m_numVisible; j++)
{
m_ppW[i][j] = kdev*Noise_Uniform(&m_noise, 0.5);
}
}
}
double **getWeights() const
{
return m_ppW;
}
double *getBiasVisible() const
{
return m_pBiasVisible;
}
double *getBiasHidden() const
{
return m_pBiasHidden;
}
void print()
{
uint32_t i, j;
double w;
printf("\n");
printf("w(v,h) = (v^, h>)\n");
for (i=0; i < m_numVisible; i++)
{
for (j=0; j < m_numHidden; j++)
{
w = m_ppW[j][i];
printf("%3.6f ", w);
}
printf("\n");
}
printf("\n");
printf("bv = \n");
for (i=0; i < m_numVisible; i++)
{
w = m_pBiasVisible[i];
printf("%3.6f\n", w);
}
printf("\n");
printf("bh = \n");
for (i=0; i < m_numHidden; i++)
{
w = m_pBiasHidden[i];
printf("%3.6f\n", w);
}
printf("\n");
}
private:
double **m_ppW;
double *m_pBiasVisible;
double *m_pBiasHidden;
uint32_t m_numVisible;
uint32_t m_numHidden;
noise_gen_t m_noise;
void alloc()
{
uint32_t i;
if (m_ppW)
{
free();
alloc();
}
else
{
m_ppW = new double*[m_numHidden];
for (i=0; i < m_numHidden; i++)
{
m_ppW[i] = new double[m_numVisible];
}
m_pBiasVisible = new double[m_numVisible];
m_pBiasHidden = new double[m_numHidden];
}
}
void free()
{
uint32_t i;
if (m_ppW)
{
for (i=0; i < m_numHidden; i++)
{
delete [] m_ppW[i];
}
delete [] m_ppW;
m_ppW = nullptr;
}
delete [] m_pBiasVisible;
m_pBiasVisible = nullptr;
delete [] m_pBiasHidden;
m_pBiasHidden = nullptr;
}
};
class Layer
{
public:
Layer(uint32_t numUnits = 0)
: m_numUnits(numUnits)
, m_pInput(nullptr)
, m_pProbs(nullptr)
, m_pStates(nullptr)
{
setNumUnits(numUnits);
Noise_Init(&m_noise, 0x12345677);
}
virtual ~Layer()
{
setNumUnits(0);
Noise_Free(&m_noise);
}
void setNumUnits(uint32_t numUnits)
{
if (m_numUnits)
{
delete [] m_pProbs;
delete [] m_pStates;
}
m_numUnits = numUnits;
if (m_numUnits)
{
uint32_t i;
m_pProbs = new double[m_numUnits];
m_pStates = new double[m_numUnits];
for (i=0; i < m_numUnits; i++)
{
m_pProbs[i] = 0.0;
}
for (i=0; i < m_numUnits; i++)
{
m_pStates[i] = 0.0;
}
}
}
Layer& operator= (const Layer &rhs)
{
memcpy(m_pProbs, rhs.m_pProbs, m_numUnits*sizeof(double));
memcpy(m_pStates, rhs.m_pStates, m_numUnits*sizeof(double));
}
void setInput(const double *pInput)
{
m_pInput = pInput;
}
void probsUpdate(const Layer &layer, const Weights &weights) const
{
uint32_t i;
for (i=0; i < m_numUnits; i++)
{
m_pProbs[i] = logSigmoid(accum(layer, weights, i));
}
}
void statesAssignfromInput()
{
if (!m_pInput)
return;
memcpy(m_pStates, m_pInput, m_numUnits*sizeof(double));
}
void statesAssignfromProbs()
{
memcpy(m_pStates, m_pProbs, m_numUnits*sizeof(double));
}
void statesUpdateStochastic()
{
uint32_t i;
double sample;
for (i=0; i < m_numUnits; i++)
{
sample = Noise_Uniform(&m_noise, 0.5);
m_pStates[i] = (double)(sample <= m_pProbs[i]);
}
}
const double *getProbs() const
{
return m_pProbs;
}
const double *getStates() const
{
return m_pStates;
}
uint32_t getNumUnits() const
{
return m_numUnits;
}
virtual double getEnergy(const Weights &weights) = 0;
private:
uint32_t m_numUnits;
const double *m_pInput;
noise_gen_t m_noise;
inline double logSigmoid(double x) const
{
return 1./(1 + exp(-x));
}
protected:
double *m_pProbs;
double *m_pStates;
virtual double accum(const Layer &layer, const Weights &weights, uint32_t index) const = 0;
};
#endif // LAYER_HPP
+160
View File
@@ -0,0 +1,160 @@
/*
==============================================================================
This file was auto-generated by the Introjucer!
It contains the basic startup code for a Juce application.
==============================================================================
*/
#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"
#include "Rbm.hpp"
//==============================================================================
class RBMApplication : public JUCEApplication
{
public:
//==============================================================================
RBMApplication()
: mainWindow(nullptr)
, m_pRbm(nullptr)
{
}
const String getApplicationName() override { return ProjectInfo::projectName; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
//==============================================================================
void initialise (const String& commandLine) override
{
double trainingData[6][16] =
{
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1},
{1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}
};
double hiddenTest[16][4] =
{
{0, 0, 0, 0},
{0, 0, 0, 1},
{0, 0, 1, 0},
{0, 0, 1, 1},
{0, 1, 0, 0},
{0, 1, 0, 1},
{0, 1, 1, 0},
{0, 1, 1, 1},
{1, 0, 0, 0},
{1, 0, 0, 1},
{1, 0, 1, 0},
{1, 0, 1, 1},
{1, 1, 0, 0},
{1, 1, 0, 1},
{1, 1, 1, 0},
{1, 1, 1, 1}
};
// Add your application's initialisation code here..
m_pRbm = new Rbm(16, 4);
// mainWindow = new MainWindow;
m_pRbm->weightsShuffle(0.01);
m_pRbm->setNumTrainingPatterns(6);
for (uint32_t i=0; i < 6; i++)
{
m_pRbm->setTrainingInput(i, trainingData[i]);
}
m_pRbm->train(10000, 0.2);
m_pRbm->prob();
/*
m_pRbm->weightsPrint();
// Test the network
for (uint32_t i=0; i < 6; i++)
{
m_pRbm->toHidden(trainingData[i]);
}
for (uint32_t i=0; i < 16; i++)
{
m_pRbm->toVisible(hiddenTest[i]);
}
*/
}
void shutdown() override
{
// Add your application's shutdown code here..
mainWindow = nullptr; // (deletes our window)
m_pRbm = nullptr;
}
//==============================================================================
void systemRequestedQuit() override
{
// This is called when the app is being asked to quit: you can ignore this
// request and let the app carry on running, or call quit() to allow the app to close.
quit();
}
void anotherInstanceStarted (const String& commandLine) override
{
// When another instance of the app is launched while this one is running,
// this method is invoked, and the commandLine parameter tells you what
// the other instance's command-line arguments were.
}
//==============================================================================
/*
This class implements the desktop window that contains an instance of
our MainContentComponent class.
*/
class MainWindow : public DocumentWindow
{
public:
MainWindow() : DocumentWindow ("RBM Gui",
Colours::lightgrey,
DocumentWindow::allButtons)
{
setContentOwned (new MainComponent(), true);
centreWithSize (getWidth(), getHeight());
setVisible (true);
}
void closeButtonPressed()
{
// This is called when the user tries to close this window. Here, we'll just
// ask the app to quit when this happens, but you can change this to do
// whatever you need.
JUCEApplication::getInstance()->systemRequestedQuit();
}
/* Note: Be careful if you override any DocumentWindow methods - the base
class uses a lot of them, so by overriding you might break its functionality.
It's best to do all your work in your content component instead, but if
you really have to override any DocumentWindow methods, make sure your
subclass also calls the superclass's method.
*/
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
ScopedPointer<MainWindow> mainWindow;
ScopedPointer<Rbm> m_pRbm;
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (RBMApplication)
+123
View File
@@ -0,0 +1,123 @@
/*
==============================================================================
This is an automatically generated GUI class created by the Introjucer!
Be careful when adding custom code to these files, as only the code within
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved.
Created with Introjucer version: 3.1.0
------------------------------------------------------------------------------
The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-13 by Raw Material Software Ltd.
==============================================================================
*/
//[Headers] You can add your own extra header files here...
//[/Headers]
#include "MainComponent.h"
//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]
//==============================================================================
MainComponent::MainComponent ()
{
addAndMakeVisible (textButton = new TextButton ("new button"));
textButton->addListener (this);
//[UserPreSize]
//[/UserPreSize]
setSize (600, 400);
//[Constructor] You can add your own custom stuff here..
//[/Constructor]
}
MainComponent::~MainComponent()
{
//[Destructor_pre]. You can add your own custom destruction code here..
//[/Destructor_pre]
textButton = nullptr;
//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]
}
//==============================================================================
void MainComponent::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]
g.fillAll (Colours::white);
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
}
void MainComponent::resized()
{
textButton->setBounds (88, 96, 150, 24);
//[UserResized] Add your own custom resize handling here..
//[/UserResized]
}
void MainComponent::buttonClicked (Button* buttonThatWasClicked)
{
//[UserbuttonClicked_Pre]
//[/UserbuttonClicked_Pre]
if (buttonThatWasClicked == textButton)
{
//[UserButtonCode_textButton] -- add your button handler code here..
//[/UserButtonCode_textButton]
}
//[UserbuttonClicked_Post]
//[/UserbuttonClicked_Post]
}
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
//[/MiscUserCode]
//==============================================================================
#if 0
/* -- Introjucer information section --
This is where the Introjucer stores the metadata that describe this GUI layout, so
make changes in here at your peril!
BEGIN_JUCER_METADATA
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
parentClasses="public Component" constructorParams="" variableInitialisers=""
snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
fixedSize="0" initialWidth="600" initialHeight="400">
<BACKGROUND backgroundColour="ffffffff"/>
<TEXTBUTTON name="new button" id="7909d74b5522987c" memberName="textButton"
virtualName="" explicitFocusOrder="0" pos="88 96 150 24" buttonText="new button"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
</JUCER_COMPONENT>
END_JUCER_METADATA
*/
#endif
//[EndFile] You can add extra defines here...
//[/EndFile]
+70
View File
@@ -0,0 +1,70 @@
/*
==============================================================================
This is an automatically generated GUI class created by the Introjucer!
Be careful when adding custom code to these files, as only the code within
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved.
Created with Introjucer version: 3.1.0
------------------------------------------------------------------------------
The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-13 by Raw Material Software Ltd.
==============================================================================
*/
#ifndef __JUCE_HEADER_9002020A4DD09B20__
#define __JUCE_HEADER_9002020A4DD09B20__
//[Headers] -- You can add your own extra header files here --
#include "JuceHeader.h"
//[/Headers]
//==============================================================================
/**
//[Comments]
An auto-generated component, created by the Introjucer.
Describe your class and how it works here!
//[/Comments]
*/
class MainComponent : public Component,
public ButtonListener
{
public:
//==============================================================================
MainComponent ();
~MainComponent();
//==============================================================================
//[UserMethods] -- You can add your own custom methods in this section.
//[/UserMethods]
void paint (Graphics& g);
void resized();
void buttonClicked (Button* buttonThatWasClicked);
private:
//[UserVariables] -- You can add your own custom variables in this section.
//[/UserVariables]
//==============================================================================
ScopedPointer<TextButton> textButton;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
//[EndFile] You can add extra defines here...
//[/EndFile]
#endif // __JUCE_HEADER_9002020A4DD09B20__
+415
View File
@@ -0,0 +1,415 @@
/*
* Rbm.hpp
*
* Created on: 21.09.2014
* Author: jens
*/
#ifndef RBM_HPP_
#define RBM_HPP_
#include "Layer.hpp"
#include <cmath>
class VisibleLayer : public Layer
{
public:
VisibleLayer(uint32_t numUnits = 0)
: Layer(numUnits)
{
}
virtual ~VisibleLayer()
{
}
double getEnergy(const Weights &weights)
{
uint32_t i;
double energy = 0;
for (i=0; i < getNumUnits(); i++)
{
energy -= weights.getBiasVisible()[i] * getStates()[i];
}
return energy;
}
private:
double accum(const Layer &layer, const Weights &weights, uint32_t index) const
{
uint32_t i;
double sum = weights.getBiasVisible()[index];
const double *pStates = layer.getStates();
for (i=0; i < layer.getNumUnits(); i++)
{
sum += pStates[i] * weights.getWeights()[i][index];
}
return sum;
}
};
class HiddenLayer : public Layer
{
public:
HiddenLayer(uint32_t numUnits = 0)
: Layer(numUnits)
{
}
virtual ~HiddenLayer()
{
}
double getEnergy(const Weights &weights)
{
uint32_t i;
double energy = 0;
for (i=0; i < getNumUnits(); i++)
{
energy -= weights.getBiasHidden()[i] * getStates()[i];
}
return energy;
}
private:
double accum(const Layer &layer, const Weights &weights, uint32_t index) const
{
uint32_t i;
double sum = weights.getBiasVisible()[index];
const double *pStates = layer.getStates();
for (i=0; i < layer.getNumUnits(); i++)
{
sum += pStates[i] * weights.getWeights()[index][i];
}
return sum;
}
};
class Rbm
{
public:
Rbm(uint32_t numVisible, uint32_t numHidden)
: m_w(numVisible, numHidden)
, m_numVisible(numVisible)
, m_numHidden(numHidden)
, m_numTrainingPatterns(0)
, m_pVisibleTraining(nullptr)
{
Noise_Init(&m_noise, 0x32727155);
}
~Rbm()
{
freeTrainingPatterns();
Noise_Free(&m_noise);
}
void setTrainingInput(uint32_t index, const double *pValues)
{
if (!m_pVisibleTraining)
return;
if (index >= m_numTrainingPatterns)
return;
m_pVisibleTraining[index].setInput(pValues);
m_pVisibleTraining[index].statesAssignfromInput();
}
void setNumTrainingPatterns(uint32_t numTrainingPatterns)
{
m_numTrainingPatterns = numTrainingPatterns;
allocTrainingPatterns();
}
void weightsUpdate(VisibleLayer &v, VisibleLayer &vr, HiddenLayer &h, HiddenLayer &hr, double mu)
{
uint32_t i, j;
double dw;
// Update weights
for (i=0; i < m_numHidden; i++)
{
dw = 0;
for (j=0; j < m_numVisible; j++)
{
dw = v.getStates()[j] * h.getStates()[i];
m_w.getWeights()[i][j] += mu*dw;
}
}
for (i=0; i < m_numHidden; i++)
{
dw = 0;
for (j=0; j < m_numVisible; j++)
{
dw = vr.getStates()[j] * hr.getStates()[i];
m_w.getWeights()[i][j] -= mu*dw;
}
}
#if 1
for (i=0; i < m_numVisible; i++)
{
dw = v.getStates()[i] - vr.getStates()[i];
m_w.getBiasVisible()[i] += mu*dw;
}
for (i=0; i < m_numHidden; i++)
{
dw = h.getStates()[i] - hr.getStates()[i];
m_w.getBiasHidden()[i] += mu*dw;
}
#endif
}
void train(uint32_t numEpochs, double mu)
{
uint32_t epoch;
uint32_t trainingPatternIndex;
VisibleLayer *pV;
VisibleLayer vr(m_numVisible);
HiddenLayer h(m_numHidden);
HiddenLayer hr(m_numHidden);
const uint32_t monitorInterval = 100; // epochs
uint32_t monitorCount = monitorInterval; // epochs
for (epoch=0; epoch < numEpochs; epoch++)
{
trainingPatternIndex = (uint32_t)((m_numTrainingPatterns)*Noise_Uniform(&m_noise, 0.5));
if (trainingPatternIndex == m_numTrainingPatterns)
continue;
// Assign training data
pV = &m_pVisibleTraining[trainingPatternIndex];
// Create hidden layer base on training data
h.probsUpdate(*pV, m_w);
// h.statesAssignfromProbs();
h.statesUpdateStochastic();
// Create visible reconstruction (a fantasy...)
vr = *pV;
vr.probsUpdate(h, m_w);
vr.statesAssignfromProbs();
// vr.statesUpdateStochastic();
// Create hidden reconstruction
hr.probsUpdate(vr, m_w);
// hr.statesAssignfromProbs();
hr.statesUpdateStochastic();
// Update weights
weightsUpdate(*pV, vr, h, hr, mu);
if (!monitorCount)
{
monitorCount = monitorInterval;
// printf("Epoch #%d\n", epoch);
// prob();
}
monitorCount--;
}
}
double getEnergy(VisibleLayer &v, HiddenLayer &h)
{
uint32_t i, j;
double energy;
energy = -v.getEnergy(m_w) - h.getEnergy(m_w);
for (i=0; i < h.getNumUnits(); i++)
{
for (j=0; j < v.getNumUnits(); j++)
{
energy -= v.getStates()[j] * h.getStates()[i] * m_w.getWeights()[i][j];
}
}
return energy;
}
void prob()
{
uint32_t i, j;
double z;
double p;
HiddenLayer *h = new HiddenLayer[m_numTrainingPatterns];
// Create hidden layer activations based on training data
for (j=0; j < m_numTrainingPatterns; j++)
{
h[j].setNumUnits(m_numHidden);
h[j].probsUpdate(m_pVisibleTraining[j], m_w);
// h[j].statesAssignfromProbs();
h[j].statesUpdateStochastic();
}
printf("pi(t) = (pi^, v>)\n");
for (i=0; i < m_numHidden; i++)
{
for (j=0; j < m_numTrainingPatterns; j++)
{
p = h[j].getProbs()[i];
printf("%3.6f ", p);
}
printf("\n");
}
printf("\n");
printf("si(t) = (si^, v>)\n");
for (i=0; i < m_numHidden; i++)
{
for (j=0; j < m_numTrainingPatterns; j++)
{
p = h[j].getStates()[i];
printf("%3.6f ", p);
}
printf("\n");
}
printf("\n");
printf("p(v) = (t^, v>)\n");
for (i=0; i < m_numTrainingPatterns; i++)
{
z = 0;
for (j=0; j < m_numTrainingPatterns; j++)
{
z += exp(-getEnergy(m_pVisibleTraining[j], h[i]));
}
for (j=0; j < m_numTrainingPatterns; j++)
{
p = exp(-getEnergy(m_pVisibleTraining[j], h[i]))/z;
printf("%3.6f ", p);
}
printf("\n");
}
printf("\n");
// Reconstruct
for (i=0; i < m_numTrainingPatterns; i++)
{
m_pVisibleTraining[i].probsUpdate(h[i], m_w);
}
printf("A fantasy... (v^, t>)\n");
for (i=0; i < m_numVisible; i++)
{
for (j=0; j < m_numTrainingPatterns; j++)
{
p = m_pVisibleTraining[j].getProbs()[i];
printf("%3.6f ", p);
}
printf("\n");
}
delete [] h;
}
void toHidden(const double *pVisible)
{
double p;
uint32_t i;
VisibleLayer v(m_numVisible);
HiddenLayer h(m_numHidden);
v.setInput(pVisible);
v.statesAssignfromInput();
h.probsUpdate(v, m_w);
printf("pi(t) = (pi^, v>)\n");
for (i=0; i < m_numHidden; i++)
{
p = h.getProbs()[i];
printf("%3.6f\n", p);
}
printf("\n");
}
void toVisible(const double *pHidden)
{
double p;
uint32_t i;
VisibleLayer v(m_numVisible);
HiddenLayer h(m_numHidden);
h.setInput(pHidden);
h.statesAssignfromInput();
v.probsUpdate(h, m_w);
printf("pi(t) = (pi^, v>)\n");
for (i=0; i < m_numVisible; i++)
{
p = v.getProbs()[i];
printf("%3.6f\n", p);
}
printf("\n");
}
void weightsPrint()
{
m_w.print();
}
void weightsShuffle(double stdDev)
{
m_w.shuffle(stdDev);
}
private:
Weights m_w;
uint32_t m_numVisible;
uint32_t m_numHidden;
uint32_t m_numTrainingPatterns;
VisibleLayer *m_pVisibleTraining;
noise_gen_t m_noise;
void allocTrainingPatterns()
{
uint32_t i;
if (m_pVisibleTraining)
{
freeTrainingPatterns();
allocTrainingPatterns();
}
else
{
m_pVisibleTraining = new VisibleLayer[m_numTrainingPatterns];
for (i=0; i < m_numTrainingPatterns; i++)
{
m_pVisibleTraining[i].setNumUnits(m_numVisible);
}
}
}
void freeTrainingPatterns()
{
uint32_t i;
if (m_pVisibleTraining)
{
delete [] m_pVisibleTraining;
m_pVisibleTraining = nullptr;
}
m_numTrainingPatterns = 0;
}
};
#endif /* RBM_HPP_ */
+79
View File
@@ -0,0 +1,79 @@
// --------------------------------------------------------------
// --------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "noise.h"
// --------------------------------------------------------------
// internal funcs
// --------------------------------------------------------------
#define PM_IA 16807
#define PM_IM 2147483647
#define PM_AM (1.0/PM_IM)
#define PM_IQ 127773
#define PM_IR 2836
#define PM_MASK 123459876
// 'Minimal' random number generator of Park and Miller. Returns a uniform random deviate
// between 0.0 and 1.0. Set or reset idum to any integer value (except the unlikely value MASK)
// to initialize the sequence; idum must not be altered between calls for successive deviates in
// a sequence.
double ran0(long *idum)
{
long k;
double ans;
*idum ^= PM_MASK; // XORing with MASK allows use of zero and other
k=(*idum)/PM_IQ; // simple bit patterns for idum.
*idum=PM_IA*(*idum-k*PM_IQ)-PM_IR *k; // Compute idum=(IA*idum) % IM without over-
// flows by Schrages method.
if (*idum < 0)
*idum += PM_IM;
ans=PM_AM*(*idum); // Convert idumto a floating result.
*idum ^= PM_MASK; // Unmask before return.
return ans;
}
// --------------------------------------------------------------
// Exported functions
// --------------------------------------------------------------
void Noise_Init(noise_gen_t *pObj, long seed)
{
pObj->state = seed;
}
void Noise_Free(noise_gen_t *pObj)
{
}
double Noise_Uniform(noise_gen_t *pObj, double mu)
{
return ran0(&pObj->state) + mu -0.5;
}
double Noise_Gaussian(noise_gen_t *pObj, double mu, double sigma)
{
double U1, U2, V1, V2, S, Y;
do
{
U1 = Noise_Uniform(pObj, 0.5); // U1=[0,1]
U2 = Noise_Uniform(pObj, 0.5); // U2=[0,1]
V1 = 2 * U1 - 1; // V1=[-1,1]
V2 = 2 * U2 - 1; // V2=[-1,1]
S = V1 * V1 + V2 * V2;
} while (S >= 1);
// X = sqrt(-2 * log(S) / S) * V1;
Y = sqrt(-2 * log(S) / S) * V2;
Y = mu + sigma*Y;
return Y;
}
+41
View File
@@ -0,0 +1,41 @@
/*
==============================================================================
noise.h
Created: 21 Sep 2014 1:55:07pm
Author: jens
==============================================================================
*/
// --------------------------------------------------------------
#ifndef _NOISE_H_
#define _NOISE_H_
// --------------------------------------------------------------
// Types
// --------------------------------------------------------------
typedef struct _snoise_gen_t
{
long state;
} noise_gen_t;
// --------------------------------------------------------------
#if defined(__cplusplus)
extern "C" {
#endif
// --------------------------------------------------------------
// Exported functions
// --------------------------------------------------------------
void Noise_Init(noise_gen_t *pObj, long seed);
void Noise_Free(noise_gen_t *pObj);
double Noise_Uniform(noise_gen_t *pObj, double mu);
double Noise_Gaussian(noise_gen_t *pObj, double mu, double sigma);
#if defined(__cplusplus)
}
#endif
// --------------------------------------------------------------
#endif // _NOISE_H_