Skip to content

Commit

Permalink
deploy: 582d053
Browse files Browse the repository at this point in the history
  • Loading branch information
mhovd committed Feb 5, 2025
1 parent b189410 commit 4e7c18a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Generates a 2-dimensional array containing Latin Hypercube Sampling points within the given ranges."><title>generate in pmcore::algorithms::routines::initialization::latin - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="pmcore" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../../pmcore/index.html">pmcore</a><span class="version">0.7.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">generate</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#arguments" title="Arguments">Arguments</a></li><li><a href="#returns" title="Returns">Returns</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In pmcore::<wbr>algorithms::<wbr>routines::<wbr>initialization::<wbr>latin</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../../../index.html">pmcore</a>::<wbr><a href="../../../index.html">algorithms</a>::<wbr><a href="../../index.html">routines</a>::<wbr><a href="../index.html">initialization</a>::<wbr><a href="index.html">latin</a></span><h1>Function <span class="fn">generate</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../../../src/pmcore/algorithms/routines/initialization/latin.rs.html#24-45">Source</a> </span></div><pre class="rust item-decl"><code>pub fn generate(
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Generates a 2-dimensional array containing Latin Hypercube Sampling points within the given ranges."><title>generate in pmcore::algorithms::routines::initialization::latin - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="pmcore" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../../pmcore/index.html">pmcore</a><span class="version">0.7.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">generate</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#arguments" title="Arguments">Arguments</a></li><li><a href="#returns" title="Returns">Returns</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In pmcore::<wbr>algorithms::<wbr>routines::<wbr>initialization::<wbr>latin</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../../../index.html">pmcore</a>::<wbr><a href="../../../index.html">algorithms</a>::<wbr><a href="../../index.html">routines</a>::<wbr><a href="../index.html">initialization</a>::<wbr><a href="index.html">latin</a></span><h1>Function <span class="fn">generate</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../../../src/pmcore/algorithms/routines/initialization/latin.rs.html#23-43">Source</a> </span></div><pre class="rust item-decl"><code>pub fn generate(
n_points: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
range_params: &amp;<a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>)&gt;,
seed: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
Expand Down
2 changes: 1 addition & 1 deletion pmcore/algorithms/routines/initialization/latin/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `latin` mod in crate `pmcore`."><title>pmcore::algorithms::routines::initialization::latin - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="pmcore" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../../pmcore/index.html">pmcore</a><span class="version">0.7.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module latin</a></h2><h3><a href="#functions">Module Items</a></h3><ul class="block"><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In pmcore::<wbr>algorithms::<wbr>routines::<wbr>initialization</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../../../index.html">pmcore</a>::<wbr><a href="../../../index.html">algorithms</a>::<wbr><a href="../../index.html">routines</a>::<wbr><a href="../index.html">initialization</a></span><h1>Module <span>latin</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../../../src/pmcore/algorithms/routines/initialization/latin.rs.html#1-66">Source</a> </span></div><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.generate.html" title="fn pmcore::algorithms::routines::initialization::latin::generate">generate</a></div><div class="desc docblock-short">Generates a 2-dimensional array containing Latin Hypercube Sampling points within the given ranges.</div></li></ul></section></div></main></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `latin` mod in crate `pmcore`."><title>pmcore::algorithms::routines::initialization::latin - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="pmcore" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../../pmcore/index.html">pmcore</a><span class="version">0.7.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module latin</a></h2><h3><a href="#functions">Module Items</a></h3><ul class="block"><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In pmcore::<wbr>algorithms::<wbr>routines::<wbr>initialization</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../../../index.html">pmcore</a>::<wbr><a href="../../../index.html">algorithms</a>::<wbr><a href="../../index.html">routines</a>::<wbr><a href="../index.html">initialization</a></span><h1>Module <span>latin</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../../../src/pmcore/algorithms/routines/initialization/latin.rs.html#1-71">Source</a> </span></div><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.generate.html" title="fn pmcore::algorithms::routines::initialization::latin::generate">generate</a></div><div class="desc docblock-short">Generates a 2-dimensional array containing Latin Hypercube Sampling points within the given ranges.</div></li></ul></section></div></main></body></html>
42 changes: 26 additions & 16 deletions src/pmcore/algorithms/routines/initialization/latin.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a></pre></div><pre class="rust"><code><span class="kw">use </span>anyhow::Result;
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a></pre></div><pre class="rust"><code><span class="kw">use </span>anyhow::Result;
<span class="kw">use </span>ndarray::prelude::<span class="kw-2">*</span>;
<span class="kw">use </span>ndarray::{Array, ArrayBase, OwnedRepr};
<span class="kw">use </span>rand::distributions::{Distribution, Uniform};
<span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;
<span class="kw">use </span>rand::rngs::StdRng;
<span class="kw">use </span>rand::seq::SliceRandom;
<span class="kw">use </span>rand::SeedableRng;
<span class="kw">use </span>rand::Rng;

<span class="doccomment">/// Generates a 2-dimensional array containing Latin Hypercube Sampling points within the given ranges.
///
Expand Down Expand Up @@ -102,8 +106,7 @@
intervals.shuffle(<span class="kw-2">&amp;mut </span>rng);

<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..n_points {
<span class="kw">let </span>u = Uniform::new(<span class="number">0.0</span>, <span class="number">1.0</span>);
<span class="kw">let </span>value = u.sample(<span class="kw-2">&amp;mut </span>rng);
<span class="kw">let </span>value = rng.random::&lt;f64&gt;();
seq[[i, j]] = min + ((intervals[i] + value) / n_points <span class="kw">as </span>f64) * (max - min);
}
}
Expand All @@ -118,16 +121,23 @@
</span><span class="kw">fn </span>test_generate_lhs() {
<span class="kw">let </span>result = generate(<span class="number">5</span>, <span class="kw-2">&amp;</span><span class="macro">vec!</span>[(<span class="number">0.</span>, <span class="number">1.</span>), (<span class="number">0.</span>, <span class="number">100.</span>), (<span class="number">0.</span>, <span class="number">1000.</span>)], <span class="number">42</span>).unwrap();
<span class="macro">assert_eq!</span>(result.shape(), <span class="kw-2">&amp;</span>[<span class="number">5</span>, <span class="number">3</span>]);
<span class="macro">assert_eq!</span>(
result,
<span class="macro">array!</span>[
[<span class="number">0.08118035164615534</span>, <span class="number">97.33000555311399</span>, <span class="number">729.2901013820507</span>],
[<span class="number">0.8068685635909911</span>, <span class="number">34.201431099281876</span>, <span class="number">969.15809885882</span>],
[<span class="number">0.682991369237072</span>, <span class="number">56.04329822650589</span>, <span class="number">299.54535567497913</span>],
[<span class="number">0.5474848855448787</span>, <span class="number">16.367227512053397</span>, <span class="number">501.1955274259167</span>],
[<span class="number">0.36985032088988323</span>, <span class="number">72.73656820048906</span>, <span class="number">11.698952289960252</span>]
]
);
<span class="comment">// Check that the values are within the expected range
</span><span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">5 </span>{
<span class="macro">assert!</span>(result[[i, <span class="number">0</span>]] &gt;= <span class="number">0. </span>&amp;&amp; result[[i, <span class="number">0</span>]] &lt;= <span class="number">1.</span>);
<span class="macro">assert!</span>(result[[i, <span class="number">1</span>]] &gt;= <span class="number">0. </span>&amp;&amp; result[[i, <span class="number">1</span>]] &lt;= <span class="number">100.</span>);
<span class="macro">assert!</span>(result[[i, <span class="number">2</span>]] &gt;= <span class="number">0. </span>&amp;&amp; result[[i, <span class="number">2</span>]] &lt;= <span class="number">1000.</span>);
}

<span class="comment">// Check that the values are different
</span><span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">5 </span>{
<span class="kw">for </span>j <span class="kw">in </span><span class="number">0</span>..<span class="number">5 </span>{
<span class="kw">if </span>i != j {
<span class="macro">assert_ne!</span>(result[[i, <span class="number">0</span>]], result[[j, <span class="number">0</span>]]);
<span class="macro">assert_ne!</span>(result[[i, <span class="number">1</span>]], result[[j, <span class="number">1</span>]]);
<span class="macro">assert_ne!</span>(result[[i, <span class="number">2</span>]], result[[j, <span class="number">2</span>]]);
}
}
}
}
}
</code></pre></div></section></main></body></html>

0 comments on commit 4e7c18a

Please sign in to comment.