Assembla home | Assembla project page
 

Changeset 178

Show
Ignore:
Timestamp:
05/22/08 17:13:46 (6 months ago)
Author:
snovik
Message:

New: RNG traits tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet.vsmdi

    r176 r178  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006"> 
     3  <TestList name="RNG traits tests" id="028c0346-c4a8-421f-910f-5e69a6d34948" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> 
     4    <TestLinks> 
     5      <TestLink id="2c8ad1d8-9257-8f7b-28d9-c01e5092e45f" name="testDefaultPoisson" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /> 
     6      <TestLink id="6cc3a76a-075f-a376-0049-5776a2109de9" name="testGaussian" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /> 
     7      <TestLink id="8d280fda-51c2-ef63-d7d7-4e5c3b00a6de" name="testCustomPoisson" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /> 
     8    </TestLinks> 
     9  </TestList> 
    310  <TestList name="Swap" id="1fb9da58-c37b-40da-9772-c8899ed4f8c6" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> 
    411    <TestLinks> 
  • trunk/QLNet/QLNet/Math/Distributions/NormalDistribution.cs

    r106 r178  
    3333              classes. 
    3434    */ 
    35     public class NormalDistribution
     35    public class NormalDistribution : IValue
    3636        private double average_, sigma_, normalizationFactor_, denominator_, derNormalizationFactor_; 
    3737 
     
    7373        Dover Publications, New York (1972) 
    7474    */ 
    75     public class CumulativeNormalDistribution
     75    public class CumulativeNormalDistribution : IValue
    7676        private double average_, sigma_; 
    7777        private NormalDistribution gaussian_ = new NormalDistribution(); 
     
    359359 
    360360    */ 
    361     public class InverseCumulativeNormal
     361    public class InverseCumulativeNormal : IValue
    362362        double average_, sigma_; 
    363363 
     
    393393 
    394394         
    395         //public InverseCumulativeNormal(double average = 0.0, double sigma   = 1.0); 
     395        public InverseCumulativeNormal() : this(0.0, 1.0) { } 
    396396        public InverseCumulativeNormal(double average, double sigma) { 
    397397            average_ = average; 
     
    465465        as QuantLib::InverseCumulativeNormal 
    466466    */ 
    467     public class MoroInverseCumulativeNormal
     467    public class MoroInverseCumulativeNormal : IValue
    468468        private double average_, sigma_; 
    469469 
  • trunk/QLNet/QLNet/Math/factorial.cs

    r118 r178  
    2828    */ 
    2929    public static class Factorial { 
    30         public static double get(int i) { 
     30        public static double get(uint i) { 
    3131            if (i<=tabulated) { 
    3232                return firstFactorials[i]; 
  • trunk/QLNet/QLNet/Math/randomnumbers/mt19937uniformrng.cs

    r170 r178  
    109109        private void seedInitialization(ulong seed) { 
    110110            /* initializes mt with a seed */ 
    111             ulong s = (seed != 0 ? seed : SeedGenerator.get()); 
     111            ulong s = (seed != 0 ? seed : SeedGenerator.instance().get()); 
    112112            mt[0]= s & 0xffffffffUL; 
    113113            for (mti=1; mti<N; mti++) { 
  • trunk/QLNet/QLNet/Math/randomnumbers/randomsequencegenerator.cs

    r170 r178  
    2323 
    2424namespace QLNet { 
     25    public interface IRNG { 
     26        int dimension(); 
     27        Sample<List<double>> nextSequence(); 
     28    } 
     29 
    2530    /*! Random sequence generator based on a pseudo-random number generator RNG. 
    2631 
     
    3237        \warning do not use with low-discrepancy sequence generator. 
    3338    */ 
    34     public class RandomSequenceGenerator<RNG> where RNG : IRNGTraits, new() { 
     39    public class RandomSequenceGenerator<RNG> : IRNG where RNG : IRNGTraits, new() { 
    3540        // typedef Sample<std::vector<Real> > sample_type; 
    3641        private int dimensionality_; 
  • trunk/QLNet/QLNet/Math/randomnumbers/rngtraits.cs

    r170 r178  
    3131 
    3232    // random number traits 
    33     public class GenericPseudoRandom<URNG, IC> where URNG : IRNGTraits, new() { 
     33    public class GenericPseudoRandom<URNG, IC> 
     34        where URNG : IRNGTraits, new() 
     35        where IC : IValue, new() { 
    3436        // data 
    35         static IC icInstance; 
     37        public static IC icInstance; 
    3638 
    3739        //// typedefs 
     
    4547 
    4648        // factory 
    47         //static InverseCumulativeRsg<RandomSequenceGenerator<URNG>,IC> make_sequence_generator(int dimension, Int64 seed) { 
    48         //    RandomSequenceGenerator<URNG> g(dimension, seed); 
    49         //    return (icInstance ? rsg_type(g, *icInstance) : rsg_type(g)); 
    50         //} 
     49        public static InverseCumulativeRsg<RandomSequenceGenerator<URNG>,IC> make_sequence_generator(int dimension, ulong seed) { 
     50            RandomSequenceGenerator<URNG> g = new RandomSequenceGenerator<URNG>(dimension, seed); 
     51            return (icInstance != null ? new InverseCumulativeRsg<RandomSequenceGenerator<URNG>, IC>(g, icInstance) 
     52                                       : new InverseCumulativeRsg<RandomSequenceGenerator<URNG>, IC>(g)); 
     53        } 
    5154    } 
    5255 
     
    5558    // typedef GenericPseudoRandom<MersenneTwisterUniformRng, InverseCumulativeNormal> PseudoRandom; 
    5659    public class PseudoRandom : GenericPseudoRandom<MersenneTwisterUniformRng, InverseCumulativeNormal> { } 
     60 
     61    //! traits for Poisson-distributed pseudo-random number generation 
     62    /*! \test sequence generators are generated and tested by comparing 
     63              samples against known good values. 
     64    */ 
     65    // typedef GenericPseudoRandom<MersenneTwisterUniformRng, InverseCumulativePoisson> PoissonPseudoRandom; 
     66    public class PoissonPseudoRandom : GenericPseudoRandom<MersenneTwisterUniformRng, InverseCumulativePoisson> { } 
    5767} 
  • trunk/QLNet/QLNet/Math/randomnumbers/seedgenerator.cs

    r168 r178  
    2828        private static MersenneTwisterUniformRng rng_; 
    2929 
     30        private static readonly SeedGenerator instance_ = new SeedGenerator(); 
    3031        private SeedGenerator() { 
    3132            rng_ = new MersenneTwisterUniformRng(42UL); 
     
    3334        } 
    3435 
    35         public static ulong get() { 
     36        public ulong get() { 
    3637            return rng_.nextInt32(); 
    3738        } 
     39 
     40        public static SeedGenerator instance() { return instance_; } 
    3841 
    3942        private void initialize() { 
  • trunk/QLNet/QLNet/QLNet.csproj

    r175 r178  
    139139    <Compile Include="Math\Distributions\GammaDistribution.cs" /> 
    140140    <Compile Include="Math\Distributions\NormalDistribution.cs" /> 
     141    <Compile Include="Math\Distributions\poissondistribution.cs" /> 
    141142    <Compile Include="Math\factorial.cs" /> 
    142143    <Compile Include="Math\integrals\Integral.cs" /> 
     
    161162    <Compile Include="Math\Optimization\Simplex.cs" /> 
    162163    <Compile Include="Math\Optimization\SteepestDescent.cs" /> 
     164    <Compile Include="Math\randomnumbers\inversecumulativerng.cs" /> 
     165    <Compile Include="Math\randomnumbers\inversecumulativersg.cs" /> 
    163166    <Compile Include="Math\randomnumbers\mt19937uniformrng.cs" /> 
    164167    <Compile Include="Math\randomnumbers\primitivepolynomials.cs" /> 
  • trunk/QLNet/QLNet/Types.cs

    r173 r178  
    2121 
    2222namespace QLNet { 
     23    // interface for all value methods 
     24    public interface IValue { 
     25        double value(double v); 
     26    } 
     27 
    2328    public struct Const { 
    2429        public const double QL_Epsilon = 2.2204460492503131e-016; 
  • trunk/QLNet/Test2008/Test2008.csproj

    r175 r178  
    88    <OutputType>Library</OutputType> 
    99    <AppDesignerFolder>Properties</AppDesignerFolder> 
    10     <RootNamespace>Test2008</RootNamespace> 
     10    <RootNamespace>TestSuite</RootNamespace> 
    1111    <AssemblyName>Test2008</AssemblyName> 
    1212    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 
     
    5656    <Compile Include="T_Operators.cs" /> 
    5757    <Compile Include="T_RiskStats.cs" /> 
     58    <Compile Include="T_RNGTraits.cs" /> 
    5859    <Compile Include="T_Rounding.cs" /> 
    5960    <Compile Include="T_SampledCurve.cs" />