Changeset 1688 for trunk/sources
- Timestamp:
- 04/28/09 15:25:09 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Random/3.3
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj
r1687 r1688 5 5 <ProductVersion>9.0.30729</ProductVersion> 6 6 <SchemaVersion>2.0</SchemaVersion> 7 <ProjectGuid>{ 47019A74-F7F7-482E-83AA-D3F4F777E879}</ProjectGuid>7 <ProjectGuid>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</ProjectGuid> 8 8 <OutputType>Library</OutputType> 9 9 <AppDesignerFolder>Properties</AppDesignerFolder> 10 10 <RootNamespace>HeuristicLab.Random</RootNamespace> 11 <AssemblyName>HeuristicLab.Random-3. 2</AssemblyName>11 <AssemblyName>HeuristicLab.Random-3.3</AssemblyName> 12 12 <SignAssembly>true</SignAssembly> 13 13 <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile> … … 17 17 <UpgradeBackupLocation> 18 18 </UpgradeBackupLocation> 19 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 19 20 </PropertyGroup> 20 21 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 36 37 <ErrorReport>prompt</ErrorReport> 37 38 <WarningLevel>4</WarningLevel> 38 <DocumentationFile>bin\Release\HeuristicLab.Random-3. 2.XML</DocumentationFile>39 <DocumentationFile>bin\Release\HeuristicLab.Random-3.3.xml</DocumentationFile> 39 40 <TreatWarningsAsErrors>false</TreatWarningsAsErrors> 40 41 </PropertyGroup> … … 75 76 <ItemGroup> 76 77 <Reference Include="System" /> 78 <Reference Include="System.Core"> 79 <RequiredTargetFramework>3.5</RequiredTargetFramework> 80 </Reference> 77 81 <Reference Include="System.Data" /> 78 82 <Reference Include="System.Drawing" /> -
trunk/sources/HeuristicLab.Random/3.3/HeuristicLabRandomPlugin.cs
r1530 r1688 29 29 /// Plugin class for HeuristicLab.Random plugin. 30 30 /// </summary> 31 [ClassInfo(Name = "HeuristicLab.Random-3.2")] 32 [PluginFile(Filename = "HeuristicLab.Random-3.2.dll", Filetype = PluginFileType.Assembly)] 33 [Dependency(Dependency = "HeuristicLab.Core-3.2")] 34 [Dependency(Dependency = "HeuristicLab.Data-3.2")] 35 [Dependency(Dependency = "HeuristicLab.Operators-3.2")] 31 [ClassInfo(Name = "HeuristicLab.Random-3.3")] 32 [PluginFile(Filename = "HeuristicLab.Random-3.3.dll", Filetype = PluginFileType.Assembly)] 33 [Dependency(Dependency = "HeuristicLab.Core-3.3")] 34 [Dependency(Dependency = "HeuristicLab.Data-3.3")] 35 [Dependency(Dependency = "HeuristicLab.Operators-3.3")] 36 [Dependency(Dependency = "HeuristicLab.Persistence-3.3")] 36 37 public class HeuristicLabRandomPlugin : PluginBase { 37 38 } -
trunk/sources/HeuristicLab.Random/3.3/MersenneTwister.cs
r1530 r1688 37 37 using System.Xml; 38 38 using HeuristicLab.Core; 39 using HeuristicLab.Persistence.Default.Decomposers.Storable; 39 40 40 41 namespace HeuristicLab.Random { … … 46 47 47 48 private object locker = new object(); 49 [Storable] 48 50 private uint[] state = new uint[n]; 51 [Storable] 49 52 private int p = 0; 53 [Storable] 50 54 private bool init = false; 51 55 … … 154 158 } 155 159 } 156 157 #region Persistence Methods158 /// <summary>159 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.160 /// </summary>161 /// <remarks>The state(s) are saved as child node with the tag <c>State</c>, each state separaated with162 /// a semicolon. Also the elements <c>p</c> and the <c>init</c> flag are saved as child nodes with163 /// tag names <c>P</c> and <c>Init</c> respectively.</remarks>164 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>165 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>166 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>167 /// <returns>The saved <see cref="XmlNode"/>.</returns>168 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {169 XmlNode node = base.GetXmlNode(name, document, persistedObjects);170 171 StringBuilder builder = new StringBuilder();172 builder.Append(state[0]);173 for (int i = 1; i < state.Length; i++) {174 builder.Append(';');175 builder.Append(state[i]);176 }177 XmlNode stateNode = document.CreateNode(XmlNodeType.Element, "State", null);178 stateNode.InnerText = builder.ToString();179 node.AppendChild(stateNode);180 181 XmlNode pNode = document.CreateNode(XmlNodeType.Element, "P", null);182 pNode.InnerText = p.ToString();183 node.AppendChild(pNode);184 185 XmlNode initNode = document.CreateNode(XmlNodeType.Element, "Init", null);186 initNode.InnerText = init.ToString();187 node.AppendChild(initNode);188 189 return node;190 }191 /// <summary>192 /// Loads the persisted random number generator from the specified <paramref name="node"/>.193 /// </summary>194 /// <remarks>The elements of the current instance must be saved in a special way, see195 /// <see cref="GetXmlNode"/>.</remarks>196 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>197 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>198 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {199 base.Populate(node, restoredObjects);200 201 string stateString = node.SelectSingleNode("State").InnerText;202 string[] tokens = stateString.Split(';');203 for (int i = 0; i < tokens.Length; i++)204 state[i] = uint.Parse(tokens[i]);205 p = int.Parse(node.SelectSingleNode("P").InnerText);206 init = bool.Parse(node.SelectSingleNode("Init").InnerText);207 }208 #endregion209 160 210 161 #region Seed Methods -
trunk/sources/HeuristicLab.Random/3.3/NormalDistributedRandom.cs
r1530 r1688 26 26 using System.Xml; 27 27 using System.Globalization; 28 using HeuristicLab.Persistence.Default.Decomposers.Storable; 28 29 29 30 namespace HeuristicLab.Random { … … 36 37 public class NormalDistributedRandom : ItemBase, IRandom { 37 38 39 [Storable] 38 40 private double mu; 39 40 41 /// <summary> 41 42 /// Gets or sets the value for µ. … … 45 46 set { mu = value; } 46 47 } 48 49 [Storable] 47 50 private double sigma; 48 49 51 /// <summary> 50 52 /// Gets or sets the value for sigma. … … 54 56 set { sigma = value; } 55 57 } 58 59 [Storable] 56 60 private IRandom uniform; 61 57 62 private double[] w = new double[] { 58 63 1.7290404664e-09, … … 513 518 /// <returns>A double random number.</returns> 514 519 public double NextDouble() { 515 double signFactor = uniform.Next() %2==0?1.0:-1.0;516 return sigma * signFactor * NextPositiveDouble() + mu;520 double signFactor = uniform.Next() % 2 == 0 ? 1.0 : -1.0; 521 return sigma * signFactor * NextPositiveDouble() + mu; 517 522 } 518 523 … … 520 525 int j = uniform.Next(); 521 526 int i = (j & 127); 522 if (Math.Abs(j) < k[i]) {527 if (Math.Abs(j) < k[i]) { 523 528 return j * w[i]; 524 529 } else { … … 526 531 double x, y; 527 532 x = j * w[i]; 528 if (i == 0) {533 if (i == 0) { 529 534 do { 530 535 x = -Math.Log(ScaledUniform()) * 0.2904764; 531 536 y = -Math.Log(ScaledUniform()); 532 } while (y + y < x * x);537 } while (y + y < x * x); 533 538 return (j > 0) ? r + x : -r - x; 534 539 } 535 if (f[i] + ScaledUniform() * (f[i - 1] - f[i]) < Math.Exp(-0.5 * x * x)) {540 if (f[i] + ScaledUniform() * (f[i - 1] - f[i]) < Math.Exp(-0.5 * x * x)) { 536 541 return x; 537 542 } else { … … 548 553 549 554 #endregion 550 551 #region persistence552 /// <summary>553 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.554 /// </summary>555 /// <remarks>The value of µ and sigma are saved as child nodes with tag names <c>Mu</c> and <c>Sigma</c>,556 /// also the random number generator is saved as a child node with tag name <c>UniformRandom</c>.</remarks>557 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>558 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>559 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>560 /// <returns>The saved <see cref="XmlNode"/>.</returns>561 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {562 XmlNode node = base.GetXmlNode(name, document, persistedObjects);563 564 XmlNode muNode = document.CreateNode(XmlNodeType.Element, "Mu", null);565 muNode.InnerText = mu.ToString("r", CultureInfo.InvariantCulture);566 node.AppendChild(muNode);567 568 XmlNode sigmaNode = document.CreateNode(XmlNodeType.Element, "Sigma", null);569 sigmaNode.InnerText = sigma.ToString("r", CultureInfo.InvariantCulture);570 node.AppendChild(sigmaNode);571 572 node.AppendChild(PersistenceManager.Persist("UniformRandom", uniform, document, persistedObjects));573 574 return node;575 }576 577 /// <summary>578 /// Loads the persisted normally distributed random variable from the specified <paramref name="node"/>.579 /// </summary>580 /// <remarks>The elements of the current instance must be saved in a special way, see581 /// <see cref="GetXmlNode"/>.</remarks>582 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>583 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>584 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {585 base.Populate(node, restoredObjects);586 587 mu = double.Parse(node.SelectSingleNode("Mu").InnerText, CultureInfo.InvariantCulture);588 sigma = double.Parse(node.SelectSingleNode("Sigma").InnerText, CultureInfo.InvariantCulture);589 uniform = (IRandom)PersistenceManager.Restore(node.SelectSingleNode("UniformRandom"), restoredObjects);590 }591 555 592 556 /// <summary> … … 602 566 return clone; 603 567 } 604 605 #endregion606 568 } 607 569 } -
trunk/sources/HeuristicLab.Random/3.3/Properties/AssemblyInfo.frame
r581 r1688 54 54 // You can specify all the values or you can default the Revision and Build Numbers 55 55 // by using the '*' as shown below: 56 [assembly: AssemblyVersion("3. 2.0.$WCREV$")]57 [assembly: AssemblyFileVersion("3. 2.0.$WCREV$")]56 [assembly: AssemblyVersion("3.3.0.$WCREV$")] 57 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")] 58 58 [assembly: AssemblyBuildDate("$WCNOW$")]
Note: See TracChangeset
for help on using the changeset viewer.