<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Microsoft Codename "Cloud Numerics"</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/cloudnumerics/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/feed.xml</link>
    <description>Model and analyze data at scale</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:21:41 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Microsoft Codename “Cloud Numerics” Lab Refresh</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/microsoft-codename-cloud-numerics-lab-refresh</link>
      <pubDate>Thu, 18 Oct 2012 06:12:00 GMT</pubDate>
      <dc:creator><![CDATA[Ronnie Hoogerwerf - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/10/18/microsoft-codename-cloud-numerics-lab-refresh/</guid>
      <description><![CDATA[We are announcing a refresh of the Microsoft Codename &quot;Cloud Numerics&quot; Lab. We want to...]]></description>
      <content:encoded><![CDATA[<p>We are announcing a refresh of the Microsoft Codename &quot;Cloud Numerics&quot; Lab. We want to thank everyone who participated in the initial lab, we amassed and used your feedback to make improvements and add exciting features. Your participation is what makes this lab a success. Thank you.</p>  <p>Here’s what is new in the refresh:</p>  <p><strong>Improved user experience</strong>: through more actionable exception messages, a refactoring of the probability distribution function APIs, and better and more actionable feedback in the deployment utility. In addition, the deployment process time has decreased and the installer supports installation on a on-premises Windows HPC Cluster. All up, this refresh provides for a more efficient way of writing and deploying “Cloud Numerics” applications to Windows Azure. </p>  <p><strong>More scale-out enabled functions</strong>: more algorithms are enabled to work on distributed arrays. This significantly increases the breadth and depth of big data algorithms that can be developed using “Cloud Numerics” Lab. Scale-out functionality was added in the following areas: Fourier transforms, linear algebra, descriptive statistics, pattern recognition, random sampling, similarity measures, set operations, and matrix math. </p>  <p><strong>Array indexing and manipulation</strong>: a large part of any data analytics application concerns handling and preparing data to be in the right shape and have the right content. With this refresh “Cloud Numerics” adds advanced array indexing enabling users to easily and efficiently set and extract subsets of arrays and to apply Boolean filters. </p>  <p><strong>Sparse data structures and algorithms</strong>: much of the real-world big data sets are sparse —not every field in a table has a value. With this refresh of the lab we introduce a distributed sparse matrix structure to hold these datasets and introduce core sparse linear algebra functions enabling scenarios such as document classification, collaborative filtering, etc.</p>  <p><strong>Apply/Sweep framework</strong>: in addition to the built-in parallelism the “Cloud Numerics” Lab, this refresh now exposes a set of APIs to enable embarrassingly parallel patterns. The Apply framework enables applying arbitrary serializable .NET code to each element of an array or to each row or column of an array. The framework also provides a set of expert level interfaces to define arbitrary array splits. The Sweep framework performs as its name implies —this framework enables distributed parameter sweeps across a set of nodes allowing for better execution times. </p>  <p><strong>Improved IO functionality</strong>: we added more parallel readers to enable out of the box data ingress from Windows Azure storage and introduced parallel writers. </p>  <p><strong>Documentation</strong>: we introduced detailed mathematical descriptions of more than half of the algorithms using print-quality formulae and best-of-web equation rendering that help clarify algorithm mathematical definition and method behavior. In addition, we updated the “Getting Started” wiki, and we added conceptual documentation for the “Cloud Numerics” help that includes the programming model, the new Apply framework, IO, and so on.</p>  <p>&#160;</p>  <p>Stay tuned for upcoming blog posts:</p>  <ul>   <li><strong>F#</strong>: We’ll be distributing a F# add-in for “Cloud Numerics” soon. The add-in exposes the “Cloud Numerics” APIs in a more functional manner, introduces operators, such as matrix multiply, and F# style constructors for and indexing on “Cloud Numerics” arrays. </li> </ul>  <ul>   <li><strong>Text analytics</strong> using sparse data structures </li> </ul>  <p>Do you want to learn more about Microsoft Codename “Cloud Numerics” Lab? Please visit us on our <a href="https://bit.ly/whsW5k">SQL Azure Labs home</a> page, take a deeper look at the <a href="https://bit.ly/xPzh76">Getting Started material</a> and <a href="https://connect.microsoft.com/SQLServer/SelfNomination.aspx?ProgramID=7720&amp;pageType=1">Sign Up</a> to get access to the installer. Let us know what you think by sending us email at <a href="mailto:cnumerics-feedback@microsoft.com">cnumerics-feedback@microsoft.com</a>.</p>  <p>The “Cloud Numerics” refresh depends on the newly released Azure SDK 1.7 and Microsoft HPC Server R2 SP4. It does not provide support for the Visual Studio 2012 RC.</p>]]></content:encoded>
    </item>
    <item>
      <title>“Cloud Numerics” F# Extensions</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-f-extensions</link>
      <pubDate>Mon, 20 Aug 2012 12:07:51 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/08/20/cloud-numerics-f-extensions/</guid>
      <description><![CDATA[In this blog post we’ll introduce Cloud Numerics F# Extensions, a companion post to Microsoft...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClassC834A684ED8643B0A34F0D0FE931E777">   <p class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">In this blog post we’ll introduce Cloud Numerics F# Extensions, a companion post to Microsoft Codename “Cloud Numerics” Lab refresh. Its purpose is to make it easier for you as an F# user to write “Cloud Numerics” applications, and it does so by wrapping “Cloud Numerics” .NET APIs to provide an F# idiomatic user experience that includes array building and manipulation and operator overloads. We’ll go through the steps of setting up the extension as well as a few examples. </p>    <p class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">The Visual Studio Solution for the extensions is available at the <a title="Microsoft Codename “Cloud Numerics” download site" href="https://connect.microsoft.com/SQLServer/SelfNomination.aspx?ProgramID=7720&amp;amp;pageType=1">Microsoft Codename “Cloud Numerics” download site</a>.</p>    <h2 class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">Set-Up on Systems with Visual Studio 2010 SP1 </h2>    <p class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">First, install “Cloud Numerics” on your local computer. If you only intend to work with compiled applications, that completes the setup. For using F# Interactive, a few additional steps are needed to enable fsi.exe for 64-bit use:</p>    <p class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">In the Programs menu, under Visual Studio Tools, right click <strong>Visual Studio x64 Win64 command prompt.</strong> Run it as administrator. In the Visual Studio tools command window, specify the following commands:</p>    <div class="ExternalClassBDAF6069E86B4FA392B9F6C72198E716">     <ul>       <li>cd C:\Program Files (x86)\Microsoft F#\v4.0 </li>        <li>copy fsi.exe fsi64.exe </li>        <li>corflags /32bit- /Force fsi64.exe </li>     </ul>   </div>    <p>Open Visual Studio</p>    <ul>     <li>From the <strong>Tools</strong> menu select <strong>Options</strong>, <strong>F# Tools</strong>, and then edit the F# Interactive Path. </li>      <li>Set the path to C:\Program Files (x86)\Microsoft F#\v4.0\fsi64.exe. </li>      <li>Restart F# Interactive. </li>   </ul>    <h2>Set-Up on Systems with Visual Studio 2012 Preview</h2>    <p>With Visual Studio 2012 preview, it is possible to use “Cloud Numerics” assemblies locally. However, because the Visual Studio project template is not available for VS 2012 preview, you’ll have to use following procedure to bypass the installation of the template:</p>    <ul>     <li>Install “Cloud Numerics” from command prompt specifying “msiexec –i MicrosoftCloudNumerics.msi CLUSTERINSTALL=1” and follow the instructions displayed by the installer for any missing prerequisites. </li>      <li>To use F# Interactive, open Visual Studio. From the Tools menu select<strong> Tools</strong>,<strong> Options</strong>, <strong>F# Tools</strong>, <strong>F# Interactive</strong>, and set “64-bit F# Interactive” to True. </li>   </ul>    <p>Note that this procedure gives the local development experience only; you can work with 64-bit F# Interactive, and build and run your application on your PC. If you have a workstation with multiple CPU cores, you can run a compiled “Cloud Numerics” application in parallel, but deployment to Windows Azure cluster is not available.</p>    <h2>Using Cloud Numerics F# Extensions from Your Project</h2>    <p>To configure your F# project to use “Cloud Numerics” F# extensions:</p>    <ul>     <li>Create F# Application in Visual Studio </li>      <li>From the <strong>Build</strong> menu, select <strong>Configuration Manager</strong>, and change the Platform attributes to x64 </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/0677.FSharpBlog1_6EDA01D0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/0677.FSharpBlog1_5F00_6EDA01D0.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="FSharpBlog1" border="0" alt="FSharpBlog1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/5852.FSharpBlog1_thumb_3AC5627D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/5852.FSharpBlog1_5F00_thumb_5F00_3AC5627D.png" width="553" height="155" /></a></p>    <ul>     <li>In the <strong>Project</strong> menu, select the <strong>Properties</strong> &lt;<em>your-application-name</em>&gt; item. From your project’s application properties tab, ensure that the target .NET Framework is 4.0, not 4.0 Client Profile. </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/1830.FSharpBlog1b_32CDC01B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/1830.FSharpBlog1b_5F00_32CDC01B.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="FSharpBlog1b" border="0" alt="FSharpBlog1b" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/2728.FSharpBlog1b_thumb_6695B66C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/2728.FSharpBlog1b_5F00_thumb_5F00_6695B66C.png" width="554" height="146" /></a></p>    <ul>     <li>Add the CloudNumericsFSharpExtensions project to your Visual Studio solution </li>      <li>Add a project reference from your application to the CloudNumericsFSharpExtensions project </li>      <li>Add references to the “Cloud Numerics” managed assemblies. These assemblies are typically located in C:\Program Files\Microsoft Cloud Numerics\v0.2\Bin </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/8117.FSharpBlog2_37CFFDCA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/8117.FSharpBlog2_5F00_37CFFDCA.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="FSharpBlog2" border="0" alt="FSharpBlog2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/0172.FSharpBlog2_thumb_16DC8B23.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/0172.FSharpBlog2_5F00_thumb_5F00_16DC8B23.png" width="249" height="304" /></a></p>    <ul>     <li>If you plan to deploy your application to Windows Azure, right-click on reference for FSharp.Core, and select <strong>Properties</strong>. In the properties window, set <strong>Copy Local</strong> to True. </li>      <li>Finally, you might need to edit the following in your .fs source file.        <br /><strong>-</strong>&#160; The code within the #if INTERACTIVE … #endif block is required only if you’re planning to use F# Interactive.         <br /><strong>-</strong>&#160; Depending on where it is located on your file system and whether you’re using Release or Debug build, you might need to adjust the path specified to CloudNumericsFSharpExtensions. </li>   </ul>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:96d4f851-1fe6-4c69-ab83-29143959662c" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">#if</span> INTERACTIVE<br> <span style="color:#808080">#I @&quot;C:&#92;Program Files&#92;Microsoft Cloud Numerics&#92;v0.2&#92;Bin&quot;</span><br> <span style="color:#808080">#I @&quot;..&#92;..&#92;..&#92;CloudNumericsFSharpExtension&#92;bin&#92;x64&#92;Release&quot;</span><br> <br> <span style="color:#808080">#r &quot;CloudNumericsFSharpExtensions&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.ManagedArrayImpl&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.DenseArrays&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Runtime&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.DistributedDenseArrays&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Math&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Statistics&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Distributed.IO&quot;</span><br> <span style="color:#0000ff">#endif</span><br> <br> <span style="color:#0000ff">open</span> Microsoft.Numerics.FSharp<br> <span style="color:#0000ff">open</span> Microsoft.Numerics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.Mathematics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.Statistics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.LinearAlgebra<br> <br> NumericsRuntime.Initialize()</div> </div> </div>    <p>&#160;</p>    <h2>Using Cloud Numerics from F# Interactive</h2>    <p>A simple way to use “Cloud Numerics” libraries from F# Interactive is to copy and send the previous piece of code to F# Interactive. Then, you will be able to use create arrays, call functions, and so forth, for example:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dc4d25a4-1269-4d72-b565-b58d98105760" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">&gt; let x = DistDense.range 1.0 1000.0;;<br> &gt; <br> val x : Distributed.NumericDenseArray&lt;float&gt;<br> <br> &gt; let y = ArrayMath.Sum(1.0/x);;<br> &gt; <br> val y : float = 7.485470861</div> </div> </div>    <p>Note that when using F# Interactive, the code executes in serial fashion. However, parallel execution is straightforward as we’ll see next.</p>    <h2>Compiling and Deploying Applications</h2>    <p>To execute your application in parallel on your workstation, build your application, open Visual Studio x64 Win64 Command Prompt, and go to the folder where your application executable is. Then, launch a parallel MPI computation using mpiexec –n &lt;number of processes&gt; &lt;application executable&gt;.</p>    <p>Let’s try the above example in parallel. The application code will look like</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:51de6aab-aacd-49e2-90be-59d406dd5ca1" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">module</span> Example<br> <br> <span style="color:#0000ff">open</span> System<br> <span style="color:#0000ff">open</span> System.Collections.Generic<br> <br> <span style="color:#0000ff">#if</span> INTERACTIVE<br> <span style="color:#808080">#I @&quot;C:&#92;Program Files&#92;Microsoft Cloud Numerics&#92;v0.2&#92;Bin&quot;</span><br> <span style="color:#808080">#I @&quot;..&#92;..&#92;..&#92;CloudNumericsFSharpExtensions&#92;bin&#92;x64&#92;Release&quot;</span><br> <br> <span style="color:#808080">#r &quot;CloudNumericsFSharpExtensions&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.ManagedArrayImpl&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.DenseArrays&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Runtime&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.DistributedDenseArrays&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Math&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Statistics&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Signal&quot;</span><br> <span style="color:#808080">#r &quot;Microsoft.Numerics.Distributed.IO&quot;</span><br> <span style="color:#0000ff">#endif</span><br> <br> <span style="color:#0000ff">open</span> Microsoft.Numerics.FSharp<br> <span style="color:#0000ff">open</span> Microsoft.Numerics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.Mathematics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.Statistics<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.LinearAlgebra<br> <span style="color:#0000ff">open</span> Microsoft.Numerics.Signal<br> <br> NumericsRuntime.Initialize()<br> <br> <span style="color:#0000ff">let</span> x = DistDense.range 1.0 1000.0<br> <span style="color:#0000ff">let</span> y = ArrayMath.Sum(1.0/x)<br> printfn <span style="color:#800000">&quot;%f&quot;</span> y</div> </div> </div>    <p>&#160;</p>    <p>You can use the same serial code in parallel case. We then run it using mpiexec to get the result:</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/6305.Capture_1C2671FF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/6305.Capture_5F00_1C2671FF.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Capture" border="0" alt="Capture" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/0842.Capture_thumb_01E608DB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/0842.Capture_5F00_thumb_5F00_01E608DB.png" width="524" height="60" /></a></p>    <table border="0" cellspacing="0" cellpadding="2" width="467"><tbody>       <tr>         <td valign="bottom" width="465"><em><strong>Note!</strong></em></td>       </tr>        <tr>         <td valign="top" width="465">First time you run an application using mpiexec, you might get a popup dialog: “Windows Firewall has blocked some features of this program”. Simply select “Allow access”.</td>       </tr>     </tbody></table>    <p>&#160;</p>    <p>Finally, to deploy the application to Azure we’ll re-purpose the “Cloud Numerics” C# Solution template to get to the Deployment Utility:</p>    <ol>     <li>Create a new “Cloud Numerics” C# Solution </li>      <li>Add your F# application project to the Solution </li>      <li>Add “Cloud Numerics” F# extensions to the Solution </li>      <li>Set AppConfigure as the Start-Up project </li>      <li>Build the Solution to get the “Cloud Numerics” Deployment Utility </li>      <li>Build the F# application </li>      <li>Use “Cloud Numerics” Deployment Utility to deploy a cluster </li>      <li>Use the “Cloud Numerics” Deployment Utility to submit a job. Instead of the default executable, select your F# application executable to be submitted </li>   </ol>    <h2>Indexing and Assignment</h2>    <p>F# has an elegant syntax for operating on slices of arrays. With “Cloud Numerics” F# Extensions we can apply this syntax to distributed arrays, for example:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c2a348a1-acfd-4994-bc6a-41ae4b64750f" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">let</span> x = DistDense.randomFloat [10L;10L]<br> <span style="color:#0000ff">let</span> y = x.[1L..3L,*]<br> x.[4L..6L,4L..6L] &lt;- x.[7L..9L,7L..9L]</div> </div> </div>    <h2>Operator Overloading</h2>    <p>We supply operator overloads for matrix multiply as x *@ y and linear solve of a*x=b as let x = a /@ b . Also, operator overloads are available for element-wise operations on arrays:</p>    <ul>     <li>Element-wise power: a.**b </li>      <li>Element-wise mod a.%b </li>      <li>Element-wise comparison: .= , .&lt; , .&lt;&gt; and so forth. </li>   </ul>    <h2>Convenience Type Definitions</h2>    <p>To enable a more concise syntax, we have added shortened definitions for the array classes as follows: </p>    <ul>     <li>LNDA&lt;’T&gt; : Microsoft.Numerics.Local.DenseArray&lt;’T&gt; </li>      <li>DNDA&lt;’T&gt; : Microsoft.Numerics.Distributed.NumericDenseArray&lt;’T&gt; </li>      <li>LNSM&lt;’T&gt; : Microsoft.Numerics.Local.SparseMatrix&lt;’T&gt; </li>      <li>DNSM&lt;’T&gt; : Microsoft.Numerics.Distributed.SparseMatrix&lt;’T&gt; </li>   </ul>    <h2>Array Building</h2>    <p>Finally, we provide several functions for building arrays, for example from F# sequences or by random sampling. They wrap the “Cloud Numerics” .NET APIs to for functional programming experience. The functions are within 4 modules:</p>    <ul>     <li>LocalDense </li>      <li>LocalSparse </li>      <li>DistDense </li>      <li>DistSparse </li>   </ul>    <p>These modules include functions for building arrays of specific type, for example:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:16f34ee1-59f7-4496-9768-69c92ede32e7" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">let</span> x = LocalDense.ofSeq [2;3;5;7;9]<br> <span style="color:#0000ff">let</span> y = DistDense.range 10 100<br> <span style="color:#0000ff">let</span> z = DistSparse.createFromTuples [(0L,3L,2.0);(1L,3L,3.0); (1L,2L, 5.0); (3L,0L,7.0)]</div> </div> </div>    <p>&#160;</p>    <h2>Building and Running Example Projects</h2>    <p>The “Cloud Numerics” F# Extensions has a folder named “Examples” that holds three example .fs files, including:</p>    <ul>     <li>A set of short examples that demonstrate how to invoke different library functions. </li>      <li>A latent semantic analysis example that demonstrates computation of correlations between different documents, in this case, SEC-10K filings of 30 Dow Jones companies. </li>      <li>A air traffic analysis example that demonstrates statistical analysis of flight arrival and delay data. </li>   </ul>    <p>The examples are part of a self-contained solution. To run them:</p>    <ul>     <li>Copy the four .csv input data files to C:\Users\Public\Documents (you can use a different folder, but you will need to adjust the path string in the source code to correspond to this folder). </li>      <li>In Solution Explorer, select an example to run by moving the .fs files up and down. </li>      <li>Build the example project and run it using mpiexec as explained before. </li>   </ul>    <p>You can also run the examples in the F# interactive, by selecting code (except the module declaration on the first line) and sending it to F# interactive.</p>    <p>This concludes the introduction to “Cloud Numerics”&#160; F# Extensions. We welcome your feedback at <a href="mailto:cnumerics-feedback@microsoft.com">cnumerics-feedback@microsoft.com</a>.</p> </div>]]></content:encoded>
    </item>
    <item>
      <title>Cloud Numerics and Latent Semantic Indexing, Now with Distributed Sparse Data</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-and-latent-semantic-indexing-now-with-distributed-sparse-data</link>
      <pubDate>Wed, 08 Aug 2012 07:14:31 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/08/08/cloud-numerics-and-latent-semantic-indexing-now-with-distributed-sparse-data/</guid>
      <description><![CDATA[&#160;  You may recall our earlier blog post about Latent Semantic Indexing and Analysis, where we...]]></description>
      <content:encoded><![CDATA[<p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">&#160;</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">You may recall our earlier <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/13/cloud-numerics-example-latent-semantic-indexing-and-analysis.aspx">blog post about Latent Semantic Indexing and Analysis</a>, where we analyzed a few hundred documents. With new features of “Cloud Numerics” Wave 2 we can repeat the analysis: not just for few hundred but for many thousands of documents. The key new features we will use are distributed sparse matrices and singular value decomposition for dimensionality reductions of sparse data. We’ll then use DataParallel.Apply to compute the cosine similarities between documents.</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The dataset we use is derived from SEC-10K filings of companies for the year of 2010. There are 8944 documents in total; the number of terms is over 100,000. We have computed the <a href="https://en.wikipedia.org/wiki/TFIDF">tfidf term-document matrix</a> and stored it as triplets (term number, document number, tfidf frequency). This matrix was computed using Hadoop and Mahout from pre-parsed filings, and then saved into a regular CSV file. We will use the “Cloud Numerics” CSV reader to read in this data. For those interested, “Cloud Numerics” can also read the triplets from the HDFS (Hadoop Distributed File System) format directly. This is a topic for another blog post.</p>  <h2>Step 1: Preparation</h2>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">To run the example, we recommend you deploy a Windows Azure cluster with two compute nodes, which you can do easily with the “Cloud Numerics” Deployment Utility. Alternatively, if you have a local computer with enough memory –-more than 8 GB free-– you can download the files (see next step) and attempt the example on that local computer. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">We’ll be creating the application --method by method-- in the steps below. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F"><strong>1.</strong>&#160; Open Visual Studio, create a new Microsoft “Cloud Numerics” Application, and call it SparseLSI.</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F"><strong>2.</strong>&#160; In the Solution Explorer frame, find the MSCloudNumericsApp project and add a reference to Microsoft.WindowsAzure.StorageClient assembly. We’ll need this assembly to read and write data to and from Azure storage. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F"><strong>3.</strong>&#160; Next, copy and paste the following piece of code to the Program.cs file as the skeleton of the application.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:439965d9-5ecc-492c-84fd-649b7a3a9ea0" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> System;<br> <span style="color:#0000ff">using</span> System.Collections.Generic;<br> <span style="color:#0000ff">using</span> System.Linq;<br> <span style="color:#0000ff">using</span> System.Text;<br> <span style="color:#0000ff">using</span> Microsoft.WindowsAzure;<br> <span style="color:#0000ff">using</span> Microsoft.WindowsAzure.StorageClient;<br> <br> <span style="color:#0000ff">using</span> Microsoft.Numerics;<br> <span style="color:#0000ff">using</span> msnl = Microsoft.Numerics.Local;<br> <span style="color:#0000ff">using</span> msnd = Microsoft.Numerics.Distributed;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Mathematics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Statistics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.LinearAlgebra;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.DataParallelOps;<br> <br> <span style="color:#0000ff">namespace</span> MSCloudNumericsApp<br> {<br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span><br>     {<br> <br>     }<br> }</div> </div> </div>  <h2 class="ExternalClass1364AE0BA5614C898A3F40722B63764F">Step 2: Copy Data to Your Own Storage Account</h2>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The input data for this application is stored at cloudnumericslab storage account: </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F"><a title="https://cloudnumericslab.blob.core.windows.net/lsidata/SEC_10K_2010.csv" href="https://cloudnumericslab.blob.core.windows.net/lsidata/SEC_10K_2010.csv">https://cloudnumericslab.blob.core.windows.net/lsidata/SEC_10K_2010.csv</a>&#160;</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">and:</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">&#160;<a title="https://cloudnumericslab.blob.core.windows.net/lsidata/Docmapping_2010.csv" href="https://cloudnumericslab.blob.core.windows.net/lsidata/Docmapping_2010.csv">https://cloudnumericslab.blob.core.windows.net/lsidata/Docmapping_2010.csv</a></p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The methods we will use to read in data to distributed arrays do not support public access to blobs, so you must copy the data to your own Windows Azure storage account. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">To do this, let’s add following methods to the “Cloud Numerics” application:</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">This routine instantiates a CloudBlobClient instance, given an account name and key: </p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:94421a7c-2dcc-438a-becd-6c334e08f68b" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> CloudBlobClient GetBlobClient(<span style="color:#0000ff">string</span> accountName, <span style="color:#0000ff">string</span> accountKey)<br> {<br>     <span style="color:#0000ff">var</span> storageAccountCredential = <span style="color:#0000ff">new</span> StorageCredentialsAccountAndKey(accountName, accountKey);<br>     <span style="color:#0000ff">var</span> storageAccount = <span style="color:#0000ff">new</span> CloudStorageAccount(storageAccountCredential, <span style="color:#0000ff">true</span>);<br>     <span style="color:#0000ff">return</span> storageAccount.CreateCloudBlobClient();<br> }</div> </div> </div>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">   <br />This method enables your application to download and upload blobs between storage accounts: </p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8ddf63fc-c489-4338-bbbc-014697d3f409" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> CopyDataToMyBlob(CloudBlobClient blobClient, <span style="color:#0000ff">string</span> originUri, <span style="color:#0000ff">string</span> destContainerName, <span style="color:#0000ff">string</span> destBlobName)<br> {<br>     <span style="color:#0000ff">var</span> originBlob = <span style="color:#0000ff">new</span> Microsoft.WindowsAzure.StorageClient.CloudBlob(originUri);<br>     <span style="color:#0000ff">var</span> destContainer = blobClient.GetContainerReference(destContainerName);<br>     destContainer.CreateIfNotExist();<br>     <span style="color:#0000ff">var</span> destBlob = destContainer.GetBlobReference(destBlobName);<br>     destBlob.UploadText(originBlob.DownloadText());<br> }</div> </div> </div>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">&#160;</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The third method copies two blobs: the CSV file that holds the term-document matrix, and a list of document names that maps term-document matrix columns to specific companies.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1b96c5da-7dfe-4eb7-bebb-fbf6d2f719f4" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> CopySecData(CloudBlobClient blobClient, <span style="color:#0000ff">string</span> myContainerName, <span style="color:#0000ff">string</span> secBlobName, <span style="color:#0000ff">string</span> mapBlobName)<br> {<br>     <span style="color:#0000ff">var</span> secUri = <span style="color:#a31515">@&quot;https://cloudnumericslab.blob.core.windows.net/lsidata/SEC_10K_2010.csv&quot;</span>;<br>     <span style="color:#0000ff">var</span> mapUri = <span style="color:#a31515">@&quot;https://cloudnumericslab.blob.core.windows.net/lsidata/Docmapping_2010.csv&quot;</span>;<br>     CopyDataToMyBlob(blobClient, secUri, myContainerName, secBlobName);<br>     CopyDataToMyBlob(blobClient, mapUri, myContainerName, mapBlobName);<br> }</div> </div> </div>  <h2 class="ExternalClass1364AE0BA5614C898A3F40722B63764F">Step 3: Read Data from the CSV File into a Sparse Matrix</h2>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">Create a method that reads data in “triplet” format (row, column, value), slices it into three vectors, and then assembles it into a sparse matrix. As an input argument, our reader will take a class that implements the IParallelReader interface, because this will give us flexibility to use the same method for data stored locally or on Azure (this point becomes more clear in Step 9). The triplet data is shaped <em>n</em>-by-3 where <em>n</em> is total number of unique words in each document of the corpus. The slicing operation yields first, second, and third column as separate vectors, where the first two correspond to indices of terms and documents, respectively. To convert them into row and column indices, we cast the first two into long integers and then call the distributed sparse matrix constructor. Add the following method to the skeleton program from previous step.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:536957bf-d508-43bd-9fe7-cddfa81b12f6" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> msnd.<span style="color:#2b91af">SparseMatrix</span>&lt;<span style="color:#0000ff">double</span>&gt; ReadTermDocMatrix(msnd.IO.<span style="color:#2b91af">IParallelReader</span>&lt;<span style="color:#0000ff">double</span>&gt; reader)<br> {<br>     <span style="color:#0000ff">var</span> triplet = msnd.IO.<span style="color:#2b91af">Loader</span>.LoadData&lt;<span style="color:#0000ff">double</span>&gt;(reader);<br>     <span style="color:#0000ff">var</span> rowIndices = triplet.GetSlice(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Slice</span>(), 0).ConvertTo&lt;<span style="color:#0000ff">long</span>&gt;();<br>     <span style="color:#0000ff">var</span> columnIndices = triplet.GetSlice(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Slice</span>(), 1).ConvertTo&lt;<span style="color:#0000ff">long</span>&gt;();<br>     <span style="color:#0000ff">var</span> nonzeroValues = triplet.GetSlice(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Slice</span>(), 2).ConvertTo&lt;<span style="color:#0000ff">double</span>&gt;();<br>     <span style="color:#0000ff">return</span> <span style="color:#0000ff">new</span> msnd.<span style="color:#2b91af">SparseMatrix</span>&lt;<span style="color:#0000ff">double</span>&gt;(rowIndices, columnIndices, nonzeroValues);<br> }</div> </div> </div>  <h2 class="ExternalClass1364AE0BA5614C898A3F40722B63764F">Step 4: Read List of Documents</h2>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">From the sparse matrix alone we cannot tell how columns map to filings by specific companies. To provide this mapping, we read in an indexed list of documents. This list was originally produced during the pre-processing of documents. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The following method reads the data file from Windows Azure to a string:</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ef5ee070-c77b-43cd-89a0-f9689c45f925" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt; ReadDocumentList(CloudBlobClient blobClient, <span style="color:#0000ff">string</span> inputContainerName, <span style="color:#0000ff">string</span> inputBlobName)<br> {<br>     <span style="color:#0000ff">var</span> resultContainer = blobClient.GetContainerReference(inputContainerName);<br>     <span style="color:#0000ff">var</span> resultBlob = resultContainer.GetBlobReference(inputBlobName);<br>     <span style="color:#0000ff">return</span> GetColumnToDocumentMapping(resultBlob.DownloadText());<br> }</div> </div> </div>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">&#160;</p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">This method converts the string into list of strings, one for each document:</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ab3e6d07-0afe-437e-a623-f7c14bc14c94" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt; GetColumnToDocumentMapping(<span style="color:#0000ff">string</span> documentList)<br> {<br>     <span style="color:#0000ff">var</span> rows = documentList.Split(<span style="color:#a31515">&#39;&#92;n&#39;</span>);<br>     <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt; columnToDocumentMap = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt;();<br>     <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> row <span style="color:#0000ff">in</span> rows)<br>     {<br>         <span style="color:#0000ff">var</span> namenum = row.Split(<span style="color:#0000ff">new</span> <span style="color:#0000ff">char</span>[] { <span style="color:#a31515">&#39;,&#39;</span> });<br>         columnToDocumentMap.Add(namenum[1].Substring(0,namenum[1].Length-1));<br>     }<br>     <span style="color:#0000ff">return</span> columnToDocumentMap;<br> }</div> </div> </div>  <h2 class="ExternalClass1364AE0BA5614C898A3F40722B63764F">Step 5: Compute Sparse Singular Value Decomposition</h2>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">The dimensionality of the term-document matrix is huge. In a sense, each document can be considered as a vector in <em>t</em>-dimensional space, where <em>t</em> is the number of words --over 100,000-- in the corpus. Also, the term-document matrix is very sparse, each document uses only a small subset of all available words. We, therefore, can reduce the dimensionality of the problem by applying singular value decomposition. </p>  <p class="ExternalClass1364AE0BA5614C898A3F40722B63764F">This SVD operation has three major effects that facilitate subsequent analysis by:</p>  <div class="ExternalClass1364AE0BA5614C898A3F40722B63764F">   <ul>     <li>Reducing noise. </li>      <li>Grouping together features that explain most of the variance between documents. </li>      <li>Reducing the dimensionality of the feature space and raw memory footprint of the data. </li>   </ul> </div>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:45b04542-1e72-4839-858a-125fae2cb1cc" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; ReduceTermDocumentMatrix(msnd.<span style="color:#2b91af">SparseMatrix</span>&lt;<span style="color:#0000ff">double</span>&gt; termDocumentMatrix, <span style="color:#0000ff">long</span> svdComponents)<br> {<br>     <span style="color:#008000">// Compute sparse SVD</span><br>     <span style="color:#0000ff">var</span> svd = <span style="color:#2b91af">Decompositions</span>.Svd(termDocumentMatrix, svdComponents);<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; sMatrix = <span style="color:#0000ff">new</span> msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt;(svd.S.Shape[0], svd.S.Shape[0]);<br>     sMatrix.Fill(0);<br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">long</span> i = 0; i &lt; svd.S.Shape[0]; i++)<br>     {<br>         sMatrix[i, i] = svd.S[i];<br>     }<br>     <span style="color:#008000">// Return (V*S). Note that after this step, rows correspond to documents</span><br>     <span style="color:#0000ff">return</span> <span style="color:#2b91af">Operations</span>.MatrixMultiply(svd.V, sMatrix);<br> }</div> </div> </div>  <p>The number of SVD components determines the reduced dimensionality. In this example we’ll specify a value of 100; you can experiment with different values. The output is a V*S matrix in reduced-dimensional subspace, which we will use for further analysis.</p>  <h2>Step 6: Compute Cosine Similarities Between Documents</h2>  <p>At this stage, each document is represented as a row vector in V*S matrix. Now, we’d like to find which documents are most similar to a specific document of interest.</p>  <p>To compare the documents we’ll use a cosine similarity measure. Let’s first add a class with a method that computes cosine similarity between a pair of documents. Note that the first vector is supplied as an argument to the constructor. The reason for this design is that we can then pass the cosine similarity method as an argument to the DataParallel.Apply(), to compute the similarity between a single document of interest and all other documents in parallel. We also mark the class as serializable so it can be passed to DataParallel.Apply().</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9d00b27e-4592-4105-a375-dd9fad90f408" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#008000">// Method for computing cosine similarities between documents</span><br> [<span style="color:#2b91af">Serializable</span>]<br> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">SimilarityComparer</span><br> {<br>     msnl.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; _documentVector1;<br>     <span style="color:#0000ff">public</span> SimilarityComparer(msnl.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; documentVector1)<br>     {<br>         _documentVector1 = documentVector1;<br>     }<br> <br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">double</span> CompareSimilarity(msnl.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; documentVector2)<br>     {<br>         <span style="color:#0000ff">double</span> sqnorm1 = <span style="color:#2b91af">ArrayMath</span>.Sum(_documentVector1*_documentVector1);<br>         <span style="color:#0000ff">double</span> sqnorm2 = <span style="color:#2b91af">ArrayMath</span>.Sum(documentVector2 * documentVector2);<br>         <span style="color:#0000ff">return</span> <span style="color:#2b91af">Operations</span>.DotProduct(_documentVector1,documentVector2) / <span style="color:#2b91af">BasicMath</span>.Sqrt(sqnorm1 * sqnorm2);<br>     }<br> <br> }</div> </div> </div>  <p>&#160;</p>  <p>Then, we’ll add a method that first looks up the row index of document of interest and gets the slice (row vector) corresponding to that document. It then instantiates SimilarityComparer using that vector, and calls DataParallel.Apply with SimilarityComparer.CompareSimilarity as the method to execute in parallel against rows of the V*S matrix. We sort the results by their similarity comparison score, select the top 10, and write the result to a string.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:79097b29-1695-4d8e-a821-dbcf6e41ae52" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> GetSimilarDocuments(<span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt; columnToDocumentMap, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; sv, <span style="color:#0000ff">string</span> interestingCompany)<br> {<br>     <span style="color:#0000ff">int</span> interestingDocIndex = columnToDocumentMap.IndexOf(interestingCompany);<br> <br>     <span style="color:#0000ff">if</span> (interestingDocIndex == -1) { <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> System.<span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;Company not found!&quot;</span>); }<br>     <span style="color:#2b91af">StringBuilder</span> output = <span style="color:#0000ff">new</span> <span style="color:#2b91af">StringBuilder</span>();<br>     <span style="color:#008000">// Compute cosine similarity</span><br>     <span style="color:#0000ff">var</span> documentVector1 = sv.GetSlice( interestingDocIndex,<span style="color:#0000ff">new</span> <span style="color:#2b91af">Slice</span>());<br> <br>     <span style="color:#0000ff">var</span> similarityComparer = <span style="color:#0000ff">new</span> <span style="color:#2b91af">SimilarityComparer</span>(documentVector1.ToLocalArray());<br> <br>     <span style="color:#0000ff">var</span> similarityResult = <span style="color:#2b91af">DataParallel</span>.Apply(similarityComparer.CompareSimilarity, sv.DimensionSplit(0));<br>     <span style="color:#0000ff">var</span> sortedSimilarity = <span style="color:#2b91af">ArrayMath</span>.ArgSort(similarityResult.Flatten(), <span style="color:#0000ff">false</span>, 0);<br>     <span style="color:#0000ff">long</span> selectedDocuments = 10;<br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">long</span> i = 0; i &lt; selectedDocuments; i++)<br>     {<br>         output.Append(columnToDocumentMap[(<span style="color:#0000ff">int</span>)sortedSimilarity.Index[i]] + <span style="color:#a31515">&quot;, &quot;</span> + sortedSimilarity.Value[i] + <span style="color:#a31515">&quot;&#92;n&quot;</span>);<br>     }<br>     <span style="color:#0000ff">return</span> output.ToString();<br> }</div> </div> </div>  <h2>Step 7: Write out Result</h2>  <p>We write the results to a Windows Azure blob as a text file. The blob is made public, so you can view the results using URI http:\\<em>&lt;myaccount&gt;</em>.cloudapp.net\lsioutput\lisresult.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9b1af055-9d97-4493-8e8d-421dc0ed2afc" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> CreateBlobAndUploadText(<span style="color:#0000ff">string</span> text, <span style="color:#2b91af">CloudBlobClient</span> blobClient, <span style="color:#0000ff">string</span> containerName, <span style="color:#0000ff">string</span> blobName)<br> {<br>     <span style="color:#0000ff">var</span> resultContainer = blobClient.GetContainerReference(containerName);<br>     resultContainer.CreateIfNotExist();<br>     <span style="color:#0000ff">var</span> resultBlob = resultContainer.GetBlobReference(blobName);<br> <br>     <span style="color:#008000">// Make result blob publicly readable so it can be accessed using URI</span><br>     <span style="color:#008000">// https://&lt;accountName&gt;.blob.core.windows.net/lsiresult/lsiresult</span><br>     <span style="color:#0000ff">var</span> resultPermissions = <span style="color:#0000ff">new</span> <span style="color:#2b91af">BlobContainerPermissions</span>();<br>     resultPermissions.PublicAccess = <span style="color:#2b91af">BlobContainerPublicAccessType</span>.Blob;<br>     resultContainer.SetPermissions(resultPermissions);<br> <br>     resultBlob.UploadText(text);<br> }</div> </div> </div>  <h2>Step 8: Put it All Together</h2>  <p>Finally, we put together the pieces in a Main method of the application: we specify the input locations, load in data, reduce the term-doc matrix, select Microsoft Corp. as a company of interest, and find similar documents. We also added a Boolean “useAzure” to provide for the optional scenario where local input and output of data is needed for cases where you want to run the application on your workstation, not on Windows Azure.</p>  <p>Note that the strings accountName, accountKey need to be changed to hold the name and key of your own Windows Azure storage account. In case you intend to run on local workstation, ensure that localPath points to the folder that holds the input files.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b72bb025-6007-4761-a041-bc7fd50785e0" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main()<br> {<br>     <span style="color:#2b91af">NumericsRuntime</span>.Initialize();<br> <br>     <span style="color:#008000">// Update these to correct Azure storage account information and</span><br>     <span style="color:#008000">// file locations on your system</span><br>     <span style="color:#0000ff">string</span> accountName = <span style="color:#a31515">&quot;myAccountName&quot;</span>;<br>     <span style="color:#0000ff">string</span> accountKey = <span style="color:#a31515">&quot;myAccountKey&quot;</span>;<br>     <span style="color:#0000ff">string</span> inputContainerName = <span style="color:#a31515">&quot;lsiinput&quot;</span>;<br>     <span style="color:#0000ff">string</span> outputContainerName = <span style="color:#a31515">&quot;lsioutput&quot;</span>;<br>     <span style="color:#0000ff">string</span> outputBlobName = <span style="color:#a31515">&quot;lsiresult&quot;</span>;<br> <br>     <span style="color:#008000">// Update this path if running locally</span><br>     <span style="color:#0000ff">string</span> localPath = <span style="color:#a31515">@&quot;C:&#92;Users&#92;Public&#92;Documents&#92;&quot;</span>;<br> <br>     <span style="color:#008000">// Not necessary to update file names</span><br>     <span style="color:#0000ff">string</span> secFileName = <span style="color:#a31515">&quot;SEC_10K_2010.csv&quot;</span>;<br>     <span style="color:#0000ff">string</span> mapFileName = <span style="color:#a31515">&quot;Docmapping_2010.csv&quot;</span>;<br>     CloudBlobClient blobClient;<br> <br>     <span style="color:#008000">// Change to false to run locally</span><br>     <span style="color:#0000ff">bool</span> useAzure = <span style="color:#0000ff">true</span>;<br> <br>     msnd.<span style="color:#2b91af">SparseMatrix</span>&lt;<span style="color:#0000ff">double</span>&gt; termDoc;<br>     <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt; columnToDocumentMap;<br> <br>     <span style="color:#008000">// Read inputs</span><br>     <span style="color:#0000ff">if</span> (useAzure)<br>     {<br>         <span style="color:#008000">// Set up CloudBlobClient</span><br>         blobClient = GetBlobClient(accountName, accountKey);<br>         <span style="color:#008000">// Copy data from Cloud Numerics Lab public blob to your local account</span><br>         CopySecData(blobClient, inputContainerName, secFileName, mapFileName);<br>         columnToDocumentMap = ReadDocumentList(blobClient, inputContainerName, mapFileName);<br>         <span style="color:#0000ff">var</span> azureCsvReader = <span style="color:#0000ff">new</span> msnd.IO.<span style="color:#2b91af">CsvSingleFromBlobReader</span>&lt;<span style="color:#0000ff">double</span>&gt;(accountName, accountKey, inputContainerName, secFileName, <span style="color:#0000ff">false</span>);<br>         termDoc = ReadTermDocMatrix(azureCsvReader);<br>     }<br>     <span style="color:#0000ff">else</span><br>     {<br>         blobClient = <span style="color:#0000ff">null</span>;<br>         <span style="color:#0000ff">var</span> dataPath = localPath + secFileName;<br>         <span style="color:#0000ff">string</span> documentList = System.IO.<span style="color:#2b91af">File</span>.ReadAllText(localPath + mapFileName);<br>         columnToDocumentMap = GetColumnToDocumentMapping(documentList);<br>         <span style="color:#0000ff">var</span> localCsvReader = <span style="color:#0000ff">new</span> msnd.IO.<span style="color:#2b91af">CsvFromDiskReader</span>&lt;<span style="color:#0000ff">double</span>&gt;(dataPath, 0, 0, <span style="color:#0000ff">false</span>);<br>         termDoc = ReadTermDocMatrix(localCsvReader);<br>     }<br> <br>     <span style="color:#008000">// Perform analysis</span><br>     <span style="color:#0000ff">long</span> svdComponents = 100;<br>     <span style="color:#0000ff">var</span> sv = ReduceTermDocumentMatrix(termDoc, svdComponents);<br> <br>     <span style="color:#0000ff">string</span> interestingCompany = <span style="color:#a31515">&quot;MICROSOFT_CORP_2010&quot;</span>;<br> <br>     <span style="color:#0000ff">string</span> output = GetSimilarDocuments(columnToDocumentMap, sv, interestingCompany);<br> <br>     <span style="color:#0000ff">if</span> (useAzure)<br>     {<br>         CreateBlobAndUploadText(output, blobClient, outputContainerName, outputBlobName);<br>     }<br>     <span style="color:#0000ff">else</span><br>     {<br>         System.IO.<span style="color:#2b91af">File</span>.WriteAllText(localPath + <span style="color:#a31515">&quot;lsiresult.csv&quot;</span>, output);<br>     }<br>     <br>     <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Done!&quot;</span>);<br>     <span style="color:#2b91af">NumericsRuntime</span>.Shutdown();<br> }</div> </div> </div>  <p>&#160;</p>  <p>Once all pieces are together, you should be ready to build and deploy the application. In Visual Studio’s Solution Explorer, Set AppConfigure Project as the StartUp Project, build and run the application, and use the “Cloud Numerics” Deployment Utility to deploy to Windows Azure. After a successful run, the resulting cosine similarities should look like the following:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/6318.blogpostw2_40515E05.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/6318.blogpostw2_5F00_40515E05.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="blogpostw2" border="0" alt="blogpostw2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/4375.blogpostw2_thumb_7823A228.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/4375.blogpostw2_5F00_thumb_5F00_7823A228.png" width="421" height="244" /></a></p>  <p>The algorithm has produced a list of technology companies as one would expect. As a sanity check, note that MICROSOFT_CORP_2010 has similarity score of 1 with itself.</p>  <p>This concludes the example; the full example code is available as a Visual Studio 2010 solution at <a href="https://bit.ly/z6K0UU">Microsoft Codename “Cloud Numerics” download site</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Cloud Numerics at Progressive F# Tutorial in NYC on June 6th</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-at-progressive-f-tutorial-in-nyc-on-june-6th</link>
      <pubDate>Tue, 22 May 2012 07:54:10 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/05/22/cloud-numerics-at-progressive-f-tutorial-in-nyc-on-june-6th/</guid>
      <description><![CDATA[We are giving a presentation about Microsoft Codename “Cloud Numerics” for F# users at Skills Matter...]]></description>
      <content:encoded><![CDATA[<p>We are giving a presentation about Microsoft Codename “Cloud Numerics” for F# users at <a href="https://skillsmatter.com/event-details/home/2012-progressive-f-tutorials-nyc/ac-4180">Skills Matter Progressive F# Tutorial</a> that takes place in NYC on June 5th and 6th. The tutorial covers many exciting F# topics; our presentation is on Wednesday 6th at 9:30am ET.</p>  <p>You may recall we posted about using <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/16/cloud-numerics-example-distributed-numerics-on-azure-with-f.aspx">Cloud Numerics and F# for distributed computing on Windows Azure</a> a while back. In the tutorial we’ll give hands-on examples of using libraries for math, linear algebra and statistics, and present demos of data analysis using Cloud Numerics and F# on Azure.</p>  <p>This is a great opportunity to learn about Cloud Numerics; don’t worry if you’re not an Azure user yet. You can try out the hands-on examples with distributed arrays and libraries using your local development environment.</p>  <p><strong>Update:</strong> Code examples for our tutorial are available for <a href="https://code.msdn.microsoft.com/Codename-Cloud-Numerics-f54830f7">download</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Tour of “Cloud Numerics” Linear Algebra Library</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/tour-of-cloud-numerics-linear-algebra-library</link>
      <pubDate>Mon, 23 Apr 2012 08:22:46 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/04/23/tour-of-cloud-numerics-linear-algebra-library/</guid>
      <description><![CDATA[Introduction    The LinearAlgebra namespace in “Cloud Numerics” is divided into 3 main classes:...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClassC3FADF9DE4EB4148A9076176951C68FA">   <h2>Introduction</h2>    <p>The LinearAlgebra namespace in “Cloud Numerics” is divided into 3 main classes:</p>    <ul>     <li>Microsoft.Numerics.LinearAlgebra.Decompositions </li>      <li>Microsoft.Numerics.LinearAlgebra.LinearSolvers </li>      <li>Microsoft.Numerics.LinearAlgebra.Operations </li>   </ul>    <p>In this post we’ll look at examples from each of the classes, and how they can be combined to implement interesting algorithms on matrices.</p>    <h2>Operations</h2>    <p>Let’s kick off the tour with an example using methods from the Operations class. We compute the largest eigenvector of a matrix by power iteration. We use Operations.MatrixMultiply to iterate the result, and Operations.Norm, first to scale the result to unit length, and then to check the convergence&#160; </p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:05be5deb-e03f-4486-97fa-2bb29d8b5297" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> System;<br> <span style="color:#0000ff">using</span> System.Text;<br> <br> <span style="color:#0000ff">using</span> Microsoft.Numerics;<br> <span style="color:#0000ff">using</span> msnl = Microsoft.Numerics.Local;<br> <span style="color:#0000ff">using</span> msnd = Microsoft.Numerics.Distributed;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Statistics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.LinearAlgebra;<br> <br> <span style="color:#0000ff">namespace</span> MSCloudNumericsApp<br> {<br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span><br>     {<br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> LargestEigenVector()<br>         {<br>             <span style="color:#0000ff">long</span> size = 20;<br>             <span style="color:#0000ff">var</span> D = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { size, size });<br>             <span style="color:#0000ff">var</span> x = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { size,1 });<br>             Microsoft.Numerics.Local.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; xnew;<br>             <span style="color:#0000ff">int</span> maxiter = 20;<br>             <span style="color:#0000ff">double</span> tol = 1E-6;<br>             <span style="color:#0000ff">int</span> iter = 0;<br>             <span style="color:#0000ff">double</span> norm = 1.0;<br>             <span style="color:#0000ff">while</span> (iter &lt; maxiter &amp;&amp; norm &gt; tol)<br>             {<br>                 iter++;<br>                 xnew = <span style="color:#2b91af">Operations</span>.MatrixMultiply(D, x);<br>                 xnew = xnew / <span style="color:#2b91af">Operations</span>.Norm(xnew,<span style="color:#2b91af">NormType</span>.TwoNorm);<br>                 norm = <span style="color:#2b91af">Operations</span>.Norm(x - xnew, <span style="color:#2b91af">NormType</span>.InfinityNorm);<br>                 x = xnew;<br>                 <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Iteration {0}:&#92;t Norm of difference: {1}&quot;</span>, iter, norm);<br>             }<br>             <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Largest eigenvector: {0}&quot;</span>, x);<br>         }<br>     }<br> }</div> </div> </div>    <p>For normalization we use the L2 norm, by passing the NormType.TwoNorm argument value. </p>    <p>For exact eigenvalues, the identity&#160; A*x=e*x should hold. We check this by comparing&#160; x and xnew: at convergence they should be close to one another. We perform the comparison by using NormType.InfinityNorm that gives the largest magnitude element-wise difference. </p>    <p>The algorithm should reach convergence after about 8 iterations.</p>    <h2>Matrix decompositions</h2>    <p>The decompositions, broadly speaking, fall into two categories</p>    <ol>     <li>Decompositions that facilitate solving systems of linear equations, for example LU and Cholesky </li>      <li>Decompositions aimed at analyzing the spectrum of a matrix, for example EigenSolve and Svd </li>   </ol>    <p>The workflow for category 1 involves computing the decomposition and passing the result object into the appropriate linear solver function. For example, one can use Cholesky decomposition as</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9212aa37-f78c-41e7-b182-da8145500858" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> choleskyDecomposition = <span style="color:#2b91af">Decompositions</span>.Cholesky(A, <span style="color:#2b91af">UpperLower</span>.UpperTriangle);<br> x = <span style="color:#2b91af">LinearSolvers</span>.Cholesky(choleskyDecomposition, b);</div> </div> </div>    <p>Because this category of methods is closely related to linear solvers, we’ll take a closer look in next section “Linear solvers”</p>    <p>The methods from category 2 can be used to represent a matrix in a form that can be analyzed more easily. Let’s try an example: singular value decomposition to compute a low-rank approximation of a matrix. In the following code, we decompose the matrix and then reconstruct it, first by keeping only the largest singular value, and then adding second largest value, and so forth. </p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2b988a7f-c937-4d6b-8ccc-78f6db53eb1d" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TestSvdConvergence()<br> {<br>     <span style="color:#0000ff">long</span> rows = 20;<br>     <span style="color:#0000ff">long</span> columns = 10;<br>     <span style="color:#0000ff">var</span> D = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { rows, columns });<br>     <span style="color:#0000ff">var</span> svdResult = <span style="color:#2b91af">Decompositions</span>.SvdThin(D);<br>     <span style="color:#0000ff">var</span> approxS = msnl.<span style="color:#2b91af">NumericDenseArrayFactory</span>.Zeros&lt;<span style="color:#0000ff">double</span>&gt;(<span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { columns, columns });<br> <br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; columns; i++)<br>     {<br>         approxS[i, i] = svdResult.S[i];<br>         <span style="color:#0000ff">var</span> reconstructedD = <span style="color:#2b91af">Operations</span>.MatrixMultiply(svdResult.U, <span style="color:#2b91af">Operations</span>.MatrixMultiply(approxS, svdResult.V));<br> <br>         <span style="color:#0000ff">double</span> norm = <span style="color:#2b91af">Operations</span>.Norm(D - reconstructedD, <span style="color:#2b91af">NormType</span>.FrobeniusNorm);<br>         <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Frobenius norm of difference with {0} singular values {1} &quot;</span>, i + 1, norm);<br>     }<br> }</div> </div> </div>    <p>We compare the reconstructed matrix to the original one by computing the Frobenius norm of the difference. As we increase the number of singular values, the norm gets smaller and smaller as the reconstructed matrix gets closer and closer to the original one. For all 10 singular values the result should be exactly the same, apart from small numerical noise.</p>    <p>Note that we are using the Decompositions.SvdThin method. This is more memory-efficient than Svd for non-square matrices. To give an example, if your data was a tall-and-thin 1 million&#160; by 100 matrix of doubles, the resulting U matrix would be a huge million by million array that consumes 8 terabytes of memory, with 999900 rows filled with zeros. However, SvdThin keeps only the 100 non-zero rows, producing a much more manageable 0.8 gigabyte array.</p>    <h2>Linear solvers</h2>    <p>There are two kinds of operations: general-purpose ones and specialized ones that can be much faster if your data has special symmetries. Consider, for example, Cholesky decomposition. If your data happens to be a symmetric positive-definite matrix, it’s much faster to compute the Cholesky decomposition first, and then use the LinearSolvers.Cholesky method to solve the linear system of equations, compared to using the general-purpose LinearSolvers.General method.</p>    <p>There’s another benefit to using specialized methods. Consider what LinearSolvers.General does under the covers: it first computes a matrix factorization internally and then solves the system of linear equations against the factorized matrix. Often, this internal factorization step is the expensive part of the computation. The factorization only depends on matrix A. If you have to compute linear solve many times against the same matrix - for example, in iteration A*x2 = f(x1), A*x3 = f(x2)&#160; - it would be nice to be able to re-use the same factorization. Using the specialized method allows you to do exactly that: pre-compute the Cholesky decomposition once and then re-use it as input to LinearSolvers.Cholesky.</p>    <p>Let’s look at an example to compare the performance of the two approaches. We’ll first need to generate a matrix that is guaranteed to be symmetric and positive-definite. First, we matrix multiply an n-by-1 and a 1-by-n random number array to create an n-by-n distributed matrix: this is an efficient way to create a large distributed matrix. Second, we add together the matrix and its transpose to create a symmetric matrix. Finally, we increase the values on the diagonal to make the matrix positive-definite: this follows from the <a href="https://en.wikipedia.org/wiki/Gershgorin_circle_theorem">Gershgorin circle theorem</a>.</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:35195fff-476e-44e8-9db7-4c1d6b0d9e0a" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; CreatePositiveDefiniteSymmetricMatrix(<span style="color:#0000ff">long</span> n)<br> {<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; columnVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n, 1 });<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; rowVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { 1, n });<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; diagVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(2.0d, 4.0d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n });<br>     <span style="color:#0000ff">var</span> A = <span style="color:#2b91af">Operations</span>.MatrixMultiply(columnVector, rowVector);<br> <br>     <span style="color:#008000">// Make matrix symmetric</span><br>     A = A + A.Transpose();<br>     <span style="color:#008000">// Increase the diagonal values to make sure the matrix is positive-definite</span><br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">long</span> i = 0; i &lt; n; i++)<br>     {<br>         A[i, i] = n * diagVector[i];<br>     }<br>     <span style="color:#0000ff">return</span> A;<br> }</div> </div> </div>    <p>&#160;</p>    <p>We’ll time 5 repeated computations of LinearSolve.General.</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b49f0819-67a3-4924-b58b-d60ae78783cc" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TimeLinearSolversGeneral(<span style="color:#0000ff">int</span> nIter, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; A, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; b, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; delta)<br> {<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; x;<br>     <span style="color:#2b91af">DateTime</span> t0 = <span style="color:#2b91af">DateTime</span>.Now;<br> <br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; nIter; i++)<br>     {<br>         x = <span style="color:#2b91af">LinearSolvers</span>.General(A, b);<br>         x = x + delta;<br>     }<br>     <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;General linear solve time: {0} seconds &quot;</span>, (<span style="color:#2b91af">DateTime</span>.Now - t0).TotalMilliseconds / 1000.0);<br> }</div> </div> </div>    <p>Next, we perform the same computation using Cholesky decomposition: we store the decomposition and re-use it as input to the LinearSolvers.Cholesky method. Note that because the matrix is assumed symmetric, the Cholesky method only uses&#160; values in its upper or lower triangle, as specified by the UpperLower argument.</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:63c30687-758e-43b6-9a7e-f6a47d46804f" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TimeLinearSolversCholesky(<span style="color:#0000ff">int</span> nIter, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; A, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; b, Microsoft.Numerics.Distributed.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; delta)<br> {<br>     msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; x;<br>     <span style="color:#2b91af">DateTime</span> t1 = <span style="color:#2b91af">DateTime</span>.Now;<br>     <span style="color:#0000ff">var</span> choleskyDecomposition = <span style="color:#2b91af">Decompositions</span>.Cholesky(A, <span style="color:#2b91af">UpperLower</span>.UpperTriangle);<br>     x = <span style="color:#2b91af">LinearSolvers</span>.Cholesky(choleskyDecomposition, b);<br> <br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; nIter; i++)<br>     {<br>         x = <span style="color:#2b91af">LinearSolvers</span>.Cholesky(choleskyDecomposition, b);<br>         x = x + delta;<br>     }<br>     <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Linear solve time using Cholesky: {0} seconds &quot;</span>, (<span style="color:#2b91af">DateTime</span>.Now - t1).TotalMilliseconds / 1000.0);<br> }</div> </div> </div>    <p>The Cholesky code should be 6-7 times faster.</p>    <h2>Examples as single code</h2>    <p>This concludes the our tour of the LinearAlgebra namespace. To try the examples yourself, you can create a Cloud Numerics application and copy-paste the code below:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8052865e-b684-4dfe-9412-eac7499d70fc" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> System;<br> <span style="color:#0000ff">using</span> System.Text;<br> <br> <span style="color:#0000ff">using</span> Microsoft.Numerics;<br> <span style="color:#0000ff">using</span> msnl = Microsoft.Numerics.Local;<br> <span style="color:#0000ff">using</span> msnd = Microsoft.Numerics.Distributed;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Statistics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.LinearAlgebra;<br> <br> <span style="color:#0000ff">namespace</span> MSCloudNumericsApp<br> {<br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span><br>     {<br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> LargestEigenVector()<br>         {<br>             <span style="color:#0000ff">long</span> size = 20;<br>             <span style="color:#0000ff">var</span> D = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { size, size });<br>             <span style="color:#0000ff">var</span> x = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { size,1 });<br>             Microsoft.Numerics.Local.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; xnew;<br>             <span style="color:#0000ff">int</span> maxiter = 20;<br>             <span style="color:#0000ff">double</span> tol = 1E-6;<br>             <span style="color:#0000ff">int</span> iter = 0;<br>             <span style="color:#0000ff">double</span> norm = 1.0;<br>             <span style="color:#0000ff">while</span> (iter &lt; maxiter &amp;&amp; norm &gt; tol)<br>             {<br>                 iter++;<br>                 xnew = <span style="color:#2b91af">Operations</span>.MatrixMultiply(D, x);<br>                 xnew = xnew / <span style="color:#2b91af">Operations</span>.Norm(xnew,<span style="color:#2b91af">NormType</span>.TwoNorm);<br>                 norm = <span style="color:#2b91af">Operations</span>.Norm(x - xnew, <span style="color:#2b91af">NormType</span>.InfinityNorm);<br>                 x = xnew;<br>                 <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Iteration {0}:&#92;t Norm of difference: {1}&quot;</span>, iter, norm);<br>             }<br>             <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Largest eigenvector: {0}&quot;</span>, x);<br>         }<br> <br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TestSvdConvergence()<br>         {<br>             <span style="color:#0000ff">long</span> rows = 20;<br>             <span style="color:#0000ff">long</span> columns = 10;<br>             <span style="color:#0000ff">var</span> D = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0d, 1d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { rows, columns });<br>             <span style="color:#0000ff">var</span> svdResult = <span style="color:#2b91af">Decompositions</span>.SvdThin(D);<br>             <span style="color:#0000ff">var</span> approxS = msnl.<span style="color:#2b91af">NumericDenseArrayFactory</span>.Zeros&lt;<span style="color:#0000ff">double</span>&gt;(<span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { columns, columns });<br> <br>             <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; columns; i++)<br>             {<br>                 approxS[i, i] = svdResult.S[i];<br>                 <span style="color:#0000ff">var</span> reconstructedD = <span style="color:#2b91af">Operations</span>.MatrixMultiply(svdResult.U, <span style="color:#2b91af">Operations</span>.MatrixMultiply(approxS, svdResult.V));<br> <br>                 <span style="color:#0000ff">double</span> norm = <span style="color:#2b91af">Operations</span>.Norm(D - reconstructedD, <span style="color:#2b91af">NormType</span>.FrobeniusNorm);<br>                 <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Frobenius norm of difference with {0} singular values {1} &quot;</span>, i + 1, norm);<br>             }<br>         }<br> <br>         <span style="color:#0000ff">static</span> msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; CreatePositiveDefiniteSymmetricMatrix(<span style="color:#0000ff">long</span> n)<br>         {<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; columnVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n, 1 });<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; rowVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { 1, n });<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; diagVector = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(2.0d, 4.0d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n });<br>             <span style="color:#0000ff">var</span> A = <span style="color:#2b91af">Operations</span>.MatrixMultiply(columnVector, rowVector);<br> <br>             <span style="color:#008000">// Make matrix symmetric</span><br>             A = A + A.Transpose();<br>             <span style="color:#008000">// Increase the diagonal values to make sure the matrix is positive-definite</span><br>             <span style="color:#0000ff">for</span> (<span style="color:#0000ff">long</span> i = 0; i &lt; n; i++)<br>             {<br>                 A[i, i] = n * diagVector[i];<br>             }<br>             <span style="color:#0000ff">return</span> A;<br>         }<br> <br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TimeLinearSolversGeneral(<span style="color:#0000ff">int</span> nIter, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; A, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; b, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; delta)<br>         {<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; x;<br>             <span style="color:#2b91af">DateTime</span> t0 = <span style="color:#2b91af">DateTime</span>.Now;<br> <br>             <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; nIter; i++)<br>             {<br>                 x = <span style="color:#2b91af">LinearSolvers</span>.General(A, b);<br>                 x = x + delta;<br>             }<br>             <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;General linear solve time: {0} seconds &quot;</span>, (<span style="color:#2b91af">DateTime</span>.Now - t0).TotalMilliseconds / 1000.0);<br>         }<br> <br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> TimeLinearSolversCholesky(<span style="color:#0000ff">int</span> nIter, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; A, msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; b, Microsoft.Numerics.Distributed.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; delta)<br>         {<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; x;<br>             <span style="color:#2b91af">DateTime</span> t1 = <span style="color:#2b91af">DateTime</span>.Now;<br>             <span style="color:#0000ff">var</span> choleskyDecomposition = <span style="color:#2b91af">Decompositions</span>.Cholesky(A, <span style="color:#2b91af">UpperLower</span>.UpperTriangle);<br>             x = <span style="color:#2b91af">LinearSolvers</span>.Cholesky(choleskyDecomposition, b);<br> <br>             <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; nIter; i++)<br>             {<br>                 x = <span style="color:#2b91af">LinearSolvers</span>.Cholesky(choleskyDecomposition, b);<br>                 x = x + delta;<br>             }<br>             <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Linear solve time using Cholesky: {0} seconds &quot;</span>, (<span style="color:#2b91af">DateTime</span>.Now - t1).TotalMilliseconds / 1000.0);<br>         }<br> <br>         <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[] args)<br>         {<br>             <span style="color:#008000">// Initialize Runtime</span><br>             <span style="color:#2b91af">NumericsRuntime</span>.Initialize();<br> <br>             LargestEigenVector();<br>             <span style="color:#008000">// Test convergence of matrix approximation from singular value decompositions</span><br>             TestSvdConvergence();<br> <br>             <span style="color:#0000ff">int</span> nIter = 5;<br>             <span style="color:#0000ff">long</span> n = 2000;<br> <br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; A = CreatePositiveDefiniteSymmetricMatrix(n);<br> <br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; b = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n });<br>             msnd.<span style="color:#2b91af">NumericDenseArray</span>&lt;<span style="color:#0000ff">double</span>&gt; delta = <span style="color:#2b91af">ProbabilityDistributions</span>.Uniform(0.1d, 0.9d, <span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { n });<br> <br> <br>             <span style="color:#008000">// Time general algorithm</span><br>             TimeLinearSolversGeneral(nIter, A, b, delta);<br> <br>             <span style="color:#008000">// Time Cholesky</span><br>             TimeLinearSolversCholesky(nIter, A, b, delta);<br> <br>             <span style="color:#008000">// Shut down the Microsoft Numerics runtime.</span><br>             <span style="color:#2b91af">NumericsRuntime</span>.Shutdown();<br>         }<br>     }<br> }</div> </div> </div> </div>]]></content:encoded>
    </item>
    <item>
      <title>“Data Transfer” and “Cloud Numerics” better together</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/data-transfer-and-cloud-numerics-better-together</link>
      <pubDate>Wed, 14 Mar 2012 03:17:03 GMT</pubDate>
      <dc:creator><![CDATA[Ronnie Hoogerwerf - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/03/14/data-transfer-and-cloud-numerics-better-together/</guid>
      <description><![CDATA[Check out a blog post from our fellow SQL Azure Lab Microsoft Codename “Data Transfer”! You can now...]]></description>
      <content:encoded><![CDATA[<p>Check out a blog post from our fellow SQL Azure Lab Microsoft Codename “Data Transfer”! You can now upload data through the Data Transfer service from on premises to Azure and use that data directly from a “Cloud Numerics” application: <a title="https://blogs.msdn.com/b/data_transfer/archive/2012/03/12/support-added-for-cloud-numerics-format.aspx" href="https://blogs.msdn.com/b/data_transfer/archive/2012/03/12/support-added-for-cloud-numerics-format.aspx">https://blogs.msdn.com/b/data_transfer/archive/2012/03/12/support-added-for-cloud-numerics-format.aspx</a>:</p>  <blockquote>   <p><em>“</em><a href="https://www.microsoft.com/en-us/sqlazurelabs/labs/numerics.aspx"><em>Microsoft Codename &quot;Cloud Numerics</em></a><em>&quot; is a SQL Azure Lab that lets you model and analyze data at scale. Now when you want to upload a file with Microsoft Codename &quot;Data Transfer&quot; to Windows Azure Blob storage for use in Cloud Numerics, you can choose to have the file converted to the Numerics Binary Format. This only applies to CSV and Excel files that contain numerical data ready for analysis with “Cloud Numerics.”</em></p>  </blockquote>  <p>To run the example application in the blog post you will need the implementation of the SequenceReader used in the example. You can download the sample reader from the “Microsoft Numerics” Connect Site (note that you need to sign up to our Connect program first). See links for <a href="https://connect.microsoft.com/site1267/SelfNomination.aspx?ProgramID=7456&amp;pageType=1">Sign-up</a> / <a href="https://connect.microsoft.com/site1267/Downloads/DownloadDetails.aspx?DownloadID=40598">Download</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>“Cloud Numerics” Example: Analyzing Air Traffic “On-Time” Data</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-example-analyzing-air-traffic-on-time-data</link>
      <pubDate>Thu, 08 Mar 2012 09:26:53 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/03/08/cloud-numerics-example-analyzing-air-traffic-on-time-data/</guid>
      <description><![CDATA[&#160;    You sit at the airport only to witness your departure time get delayed. You wait. Your...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClassFF5C9FF0FC5F4367B3C2AE6520907CEA">   <p class="ExternalClassF21282A7530D43E8994D09E71C07E88E">&#160;</p>    <p class="ExternalClassF21282A7530D43E8994D09E71C07E88E">You sit at the airport only to witness your departure time get delayed. You wait. Your flight gets delayed again, and you wonder “what’s happening?” Can you predict how long it will take to arrive at your destination? Are there many short delays in front of you or just a few long delays? This example demonstrates how you can use “Cloud Numerics” to sift though and calculate a big enough cross section of air traffic data needed to answer these questions. We will use on-time performance data from the U.S. Department of Transportation to analyze the distribution of delays. The data is available at:</p>    <p class="ExternalClassF21282A7530D43E8994D09E71C07E88E"><a title="https://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=236&amp;DB_Short_Name=On-Time" href="https://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=236&amp;DB_Short_Name=On-Time">https://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=236&amp;DB_Short_Name=On-Time</a></p>    <p class="ExternalClassF21282A7530D43E8994D09E71C07E88E">This data set holds data for every scheduled flight in the U.S. from 1987 to 2011 and is —as one would expect— huge! For your convenience, we have uploaded a sample of 32 months —one file per month with about 500,000 flights in each— to Windows Azure Blob Storage at container URI: https://cloudnumericslab.blob.core.windows.net/flightdata (note that you cannot access this URI directly in a browser, you must use a Storage Client C# APIs as in Step 2, or a <a href="https://cloudnumericslab.blob.core.windows.net/flightdata?restype=container&amp;comp=list">REST API query</a>).</p>    <h2 class="ExternalClassF21282A7530D43E8994D09E71C07E88E">Before You Begin</h2>    <div class="ExternalClassF21282A7530D43E8994D09E71C07E88E">     <ul>       <li>You will need to have <a href="https://www.microsoft.com/en-us/sqlazurelabs/labs/numerics.aspx">Microsoft Codename “Cloud Numerics”</a> installed. </li>        <li>Create a Windows Azure subscription for deploying and running the application (if do not have one already). You also need a Windows Azure storage account set up for saving results. </li>        <li><a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_install_cloud_numerics">Install “Cloud Numerics”</a> on your local computer where you develop your C# applications. </li>        <li>Run the example application as detailed in the “Cloud Numerics” Lab <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_run_a_distributed_application_over_azure">Getting Started</a> wiki page to validate your installation. </li>     </ul>   </div>    <p>You should use two-to-four compute nodes when deploying the application to Windows Azure. One node might not have enough memory, and for larger-sized deployments there are not enough files in the sample data set to assign to all distributed I/O processes. You should not attempt to run the application on a local system because of data transfer and memory requirements.</p>    <table border="0" cellspacing="0" cellpadding="2" width="554"><tbody>       <tr>         <td valign="bottom" width="552"><em><strong>Note!</strong></em></td>       </tr>        <tr>         <td valign="top" width="552">You specify how many compute nodes are allocated when you use the Cloud Numerics Deployment Utility to configure your Windows Azure cluster. For details, see <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_Ref310275063">this</a> section in the <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx">Getting Started</a> guide.</td>       </tr>     </tbody></table>    <h2>Step 1: Create Cloud Numerics project</h2>    <p>First, let’s create a Cloud Numerics application using the Cloud Numerics Visual Studio project template.</p>    <p>1.&#160; Start Microsoft Visual Studio and create a solution from the Cloud Numerics project template. Let’s call the solution “OnTimeStats.” </p>    <p>2.&#160; Create a new application, and delete the sample code from within the MSCloudNumericsApp subproject’s Program.cs file. Replace it with the following skeleton of an application.</p>    <p>&#160;</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1e8a5c15-ab30-475f-8bb3-386fcd0703b7" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> System;<br> <span style="color:#0000ff">using</span> System.Collections.Generic;<br> <span style="color:#0000ff">using</span> System.Linq;<br> <span style="color:#0000ff">using</span> System.Text;<br> <span style="color:#0000ff">using</span> msnl = Microsoft.Numerics.Local;<br> <span style="color:#0000ff">using</span> msnd = Microsoft.Numerics.Distributed;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Statistics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Mathematics;<br> <span style="color:#0000ff">using</span> Microsoft.Numerics.Distributed.IO;<br> <span style="color:#0000ff">using</span> Microsoft.WindowsAzure;<br> <span style="color:#0000ff">using</span> Microsoft.WindowsAzure.StorageClient;<br> <br> <span style="color:#0000ff">namespace</span> FlightOnTime<br> {    <br>     [<span style="color:#2b91af">Serializable</span>]<br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">FlightInfoReader</span> : <span style="color:#2b91af">IParallelReader</span>&lt;<span style="color:#0000ff">double</span>&gt;<br>     {<br> <br> <br>     }<br> <br>     <span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span><br>     {<br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> WriteOutput(<span style="color:#0000ff">string</span> output)<br>         {<br> <br>         }<br> <br>         <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main()<br>         {<br>             <span style="color:#008000">// Initialize runtime</span><br>             Microsoft.Numerics.<span style="color:#2b91af">NumericsRuntime</span>.Initialize();<br> <br> <br>             <span style="color:#008000">// Shut down runtime</span><br>             Microsoft.Numerics.<span style="color:#2b91af">NumericsRuntime</span>.Shutdown();<br>         }<br>     }<br> }</div> </div> </div>    <p>&#160;</p>    <p>3.&#160; Add a .NET reference to Microsoft.WindowsAzure.StorageClient. This assembly is used for reading in data from blobs, and writing results.</p>    <h2>Step 2: Add Methods for Reading Data</h2>    <p>We’ll use the <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/18/cloud-numerics-example-using-the-iparallelreader-interface.aspx">IParallelReader</a> interface to read in the data from blob storage in the following manner:</p>    <ul>     <li>In the ComputeAssignment method, we must first list the blobs in the container that holds the flight data (<a title="https://cloudnumericslab.blob.core.windows.net/flightdata" href="https://cloudnumericslab.blob.core.windows.net/flightdata">https://cloudnumericslab.blob.core.windows.net/flightdata</a>). Then, we assign blobs to each worker node, in round-robin fashion. </li>      <li>In the ReadWorker method, we instantiate a list “arrivalDelays”. Each reader will then open the first blob on their list, download the text, break it to lines, break the line to columns, and select column 44 that holds the arrival delays in minutes. Note that if a flight was canceled or diverted, this value is blank and we must skip the row. We convert the result to a double precision type and append it to the arrivalDelays list. Then, we either move to the next blob or –if done– convert the list into NumericDenseArray and return it. </li>   </ul>    <p>For Step 2, add the following code to the FlightInforReader class in your skeleton application.</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ac140f7-9b33-43a4-9341-dd1a1f3f298a" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">[Serializable]<br> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> FlightInfoReader : IParallelReader&lt;<span style="color:#0000ff">double</span>&gt;<br> {<br> <br>     <span style="color:#0000ff">string</span> _containerAddress;<br> <br>     <span style="color:#0000ff">public</span> FlightInfoReader(<span style="color:#0000ff">string</span> containerAddress)<br>     {<br>         _containerAddress = containerAddress;<br>     }<br> <br>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> DistributedDimension<br>     {<br>         <span style="color:#0000ff">get</span> {<span style="color:#0000ff">return</span> 0;}<br>         <span style="color:#0000ff">set</span> {}<br>     }<br> <br>     <span style="color:#0000ff">public</span> Object[] ComputeAssignment(<span style="color:#0000ff">int</span> ranks)<br>     {<br>         <span style="color:#008000">// Get list of flight info files (blobs) from container</span><br>         var container = <span style="color:#0000ff">new</span> CloudBlobContainer(_containerAddress);<br>         var blobs = container.ListBlobs().ToArray();<br> <br>         <span style="color:#008000">// Allocate blobs to workers in round-robin fashion</span><br>         List&lt;Uri&gt; [] assignments = <span style="color:#0000ff">new</span> List&lt;Uri&gt; [ranks];<br>         <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; ranks; i++)<br>         {<br>             assignments[i] = <span style="color:#0000ff">new</span> List&lt;Uri&gt;();<br>         }<br> <br>         <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 0; i &lt; blobs.Count(); i++)<br>         {<br>             <span style="color:#0000ff">int</span> currentRank = i % ranks;<br>             assignments[currentRank].Add(blobs[i].Uri);<br>         }<br>         <span style="color:#0000ff">return</span> (Object[]) assignments;<br>     }<br> <br>     <span style="color:#0000ff">public</span> msnl.NumericDenseArray&lt;<span style="color:#0000ff">double</span>&gt; ReadWorker(Object assignment)<br>     {<br>         <br>         List&lt;Uri&gt; assignmentUris = (List&lt;Uri&gt;) assignment;<br> <br>         <span style="color:#008000">// If there are no blobs to read, return empty array</span><br>         <span style="color:#0000ff">if</span> (assignmentUris.Count == 0)<br>         {<br>             <span style="color:#0000ff">return</span> msnl.NumericDenseArrayFactory.Create&lt;<span style="color:#0000ff">double</span>&gt;(<span style="color:#0000ff">new</span> <span style="color:#0000ff">long</span>[] { 0 });<br>         }<br> <br>         List&lt;<span style="color:#0000ff">double</span>&gt; arrivalDelays = <span style="color:#0000ff">new</span> List&lt;<span style="color:#0000ff">double</span>&gt;();<br> <br>         <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> blobCount = 0; blobCount &lt; assignmentUris.Count; blobCount++)<br>         {<br>             <span style="color:#008000">// Open blob and read text lines</span><br>             var blob = <span style="color:#0000ff">new</span> CloudBlob(assignmentUris[blobCount].AbsoluteUri);<br>             var rows = blob.DownloadText().Split(<span style="color:#0000ff">new</span> <span style="color:#0000ff">char</span>[] {<span style="color:#a31515">&#39;&#92;n&#39;}</span>);<br>             <span style="color:#0000ff">int</span> nrows = rows.Count();<br> <br>             <span style="color:#008000">// Offset by one row because of header file, also, note that last row is empty</span><br>             <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = 1; i &lt; nrows - 1; i++)<br>             {<br>                 <span style="color:#008000">// Remove quotation marks and split row</span><br>                 var thisRow = rows[i].Replace(<span style="color:#a31515">&quot;&#92;&quot;&quot;</span>, String.Empty).Split(<span style="color:#0000ff">new</span> <span style="color:#0000ff">char</span>[] { <span style="color:#a31515">&#39;,&#39;</span> });<br>  <br>                 <span style="color:#008000">// Filter out canceled and diverted flights</span><br>                 <span style="color:#0000ff">if</span> (!thisRow[49].Contains(<span style="color:#a31515">&quot;1&quot;</span>) &amp;&amp; !thisRow[51].Contains(<span style="color:#a31515">&quot;1&quot;</span>))<br>                 {<br>                     <span style="color:#008000">// Add arrival delay from column 44 to list</span><br>                     arrivalDelays.Add(System.Convert.ToDouble(thisRow[44]));<br>                 }<br>             }<br>         }<br>         <span style="color:#008000">// Convert list to numeric dense array and return it from reader</span><br>         <span style="color:#0000ff">return</span> msnl.NumericDenseArrayFactory.CreateFromSystemArray&lt;<span style="color:#0000ff">double</span>&gt;(arrivalDelays.ToArray());<br>     }<br> }</div> </div> </div>    <p>&#160;</p>    <table border="0" cellspacing="0" cellpadding="2" width="540"><tbody>       <tr>         <td valign="bottom" width="538"><em><strong>Note!</strong></em></td>       </tr>        <tr>         <td valign="top" width="538">See the blog post titled <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/18/cloud-numerics-example-using-the-iparallelreader-interface.aspx">“Cloud Numerics” Example: Using the IParallelReader Interface</a> for more details on how to use the IParallelReader interface. </td>       </tr>     </tbody></table>    <h2>Step 3: Implement the Algorithm</h2>    <p>After reading in the delays, we compute mean, we center the data to the mean (to make the worse-than-average delays positive and better-than-average ones negative), and then compute sample standard deviation. Then, to analyze the distribution of data, we count how many flights, on average, are more than k standard deviations away from the mean. Also, we keep track how many flights are above or below to mean, so as to detect any skew in data.</p>    <p>For example, if the data were normal distributed one would expect it to be symmetric around the mean, and obey the <a href="https://en.wikipedia.org/wiki/68-95-99.7_rule">three-sigma rule</a> —or, equivalently, about 16% of flights would be delayed by more than 1 standard deviation, 2.2 % by more than 2 standard deviations and 0.13% by more than 3. </p>    <p>To implement the algorithm, we add following code as the Main method to the application.</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:16156620-18f5-48c2-ac9f-39fea84b4ff9" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main()<br> {<br>     <span style="color:#008000">// Initialize runtime</span><br>     Microsoft.Numerics.<span style="color:#2b91af">NumericsRuntime</span>.Initialize();<br> <br>     <span style="color:#008000">// Instantiate StringBuilder for writing output</span><br>     <span style="color:#2b91af">StringBuilder</span> output = <span style="color:#0000ff">new</span> <span style="color:#2b91af">StringBuilder</span>();<br> <br>     <span style="color:#008000">// Read flight info</span><br>     <span style="color:#0000ff">string</span> containerAddress = <span style="color:#a31515">@&quot;https://cloudnumericslab.blob.core.windows.net/flightdata/&quot;</span>;<br>     <span style="color:#0000ff">var</span> flightInfoReader = <span style="color:#0000ff">new</span> <span style="color:#2b91af">FlightInfoReader</span>(containerAddress);<br>     <span style="color:#0000ff">var</span> flightData = <span style="color:#2b91af">Loader</span>.LoadData&lt;<span style="color:#0000ff">double</span>&gt;(flightInfoReader);<br> <br>     <span style="color:#008000">// Compute mean and standard deviation</span><br>     <span style="color:#0000ff">var</span> nSamples = flightData.Shape[0];<br>     <span style="color:#0000ff">var</span> mean = <span style="color:#2b91af">Descriptive</span>.Mean(flightData);<br>     flightData = flightData - mean;<br>     <span style="color:#0000ff">var</span> stDev = <span style="color:#2b91af">BasicMath</span>.Sqrt(<span style="color:#2b91af">Descriptive</span>.Mean(flightData * flightData) * ((<span style="color:#0000ff">double</span>)nSamples / (<span style="color:#0000ff">double</span>)(nSamples - 1)));<br> <br>     output.AppendLine(<span style="color:#a31515">&quot;Mean (minutes), &quot;</span> + mean);<br>     output.AppendLine(<span style="color:#a31515">&quot;Standard deviation (minutes), &quot;</span> + stDev);<br> <br>     <span style="color:#008000">// Compute how much of the data is below or above 0, 1,...,5 standard deviations</span><br> <br>     <span style="color:#0000ff">long</span> nStDev = 6;<br>     <span style="color:#0000ff">for</span> (<span style="color:#0000ff">long</span> k = 0; k &lt; nStDev; k++)<br>     {<br>         <span style="color:#0000ff">double</span> aboveKStDev = 100d * <span style="color:#2b91af">Descriptive</span>.Mean((flightData &gt; k * stDev).ConvertTo&lt;<span style="color:#0000ff">double</span>&gt;());<br>         <span style="color:#0000ff">double</span> belowKStDev = 100d * <span style="color:#2b91af">Descriptive</span>.Mean((flightData &lt; -k * stDev).ConvertTo&lt;<span style="color:#0000ff">double</span>&gt;());<br>         output.AppendLine(<span style="color:#a31515">&quot;Samples below and above k standard deviations (percent), &quot;</span> + k + <span style="color:#a31515">&quot;, &quot;</span> + belowKStDev + <span style="color:#a31515">&quot;, &quot;</span> + aboveKStDev);<br>     }<br> <br>     <span style="color:#008000">// Write output to a blob</span><br>     WriteOutput(output.ToString());<br> <br>     <span style="color:#008000">// Shut down runtime</span><br>     Microsoft.Numerics.<span style="color:#2b91af">NumericsRuntime</span>.Shutdown();<br> }</div> </div> </div>    <h2>Step 4: Write Results to a Blob</h2>    <p>We add the WriteOutput method that writes results to binary large object (blob) storage as .csv-formatted text.&#160; The WriteOutput method will create a container “flightdataresult” and a blob “flightdataresult.csv.” You can then view this blob by opening your file in Excel. For example: <strong>https://&lt;myAccountName&gt;.blob.core.windows.net/flightdataresult/flightdataresult.csv</strong> </p>    <p>--Where &lt;myAccountName&gt; is the name of your Windows Azure account.</p>    <p>Let’s fill in the last missing piece from the application, the WriteOutput method, with following code. </p>    <p>Note that you’ll have to change &quot;myAccountKey&quot; and &quot;myAccountName&quot; to reflect your own storage account key and name. </p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c9c215e0-2617-422f-939b-43547c1bf4ba" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> WriteOutput(<span style="color:#0000ff">string</span> output)<br> {<br>     <span style="color:#008000">// Write to blob storage</span><br>     <span style="color:#008000">// Replace &quot;myAccountKey&quot; and &quot;myAccountName&quot; by your own storage account key and name</span><br>     <span style="color:#0000ff">string</span> accountKey = <span style="color:#a31515">&quot;myAccountKey&quot;</span>;<br>     <span style="color:#0000ff">string</span> accountName = <span style="color:#a31515">&quot;myAccountName&quot;</span>;<br>     <span style="color:#008000">// Result blob and container name</span><br>     <span style="color:#0000ff">string</span> containerName = <span style="color:#a31515">&quot;flightdataresult&quot;</span>;<br>     <span style="color:#0000ff">string</span> blobName = <span style="color:#a31515">&quot;flightdataresult.csv&quot;</span>;<br> <br>     <span style="color:#008000">// Create result container and blob</span><br>     var storageAccountCredential = <span style="color:#0000ff">new</span> StorageCredentialsAccountAndKey(accountName, accountKey);<br>     var storageAccount = <span style="color:#0000ff">new</span> CloudStorageAccount(storageAccountCredential, <span style="color:#0000ff">true</span>);<br>     var blobClient = storageAccount.CreateCloudBlobClient();<br>     var resultContainer = blobClient.GetContainerReference(containerName);<br>     resultContainer.CreateIfNotExist();<br>     var resultBlob = resultContainer.GetBlobReference(blobName);<br> <br>     <span style="color:#008000">// Make result blob publicly readable,</span><br>     var resultPermissions = <span style="color:#0000ff">new</span> BlobContainerPermissions();<br>     resultPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;<br>     resultContainer.SetPermissions(resultPermissions);<br> <br>     <span style="color:#008000">// Upload result to blob</span><br>     resultBlob.UploadText(output);<br> }</div> </div> </div>    <p>&#160;</p>    <h2>Step 5: Deploy the Application and Analyze Results</h2>    <p>Now, you are ready to run the application. Set AppConfigure as the startup project, build the application, and use the Cloud Numerics Deployment Utility to deploy and run the application.</p>    <p>Let’s take a look at the results. We can immediately see they’re not normal-distributed at all. First, there’s skew —about 70% of the flight delays are better than average of 5 minute. Second, the number of delays tails off much more gradually than a normal distribution would as one moves away from the mean towards longer delays. A step of one standard deviation (about 35 minutes) roughly halves the number of delays, as we can see in the sequence 8.5 %,&#160; 4.0 %, 2.1%, 1.1 %, 0.6 %. These findings suggests that the tail could be modeled by an exponential distribution.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/1447.flightanalysisresult_748AB434.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/1447.flightanalysisresult_5F00_748AB434.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="flightanalysisresult" border="0" alt="flightanalysisresult" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/4162.flightanalysisresult_thumb_6C9311D2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/4162.flightanalysisresult_5F00_thumb_5F00_6C9311D2.png" width="554" height="163" /></a></p>    <p>This result is both good news and bad news for you as a passenger. There is a good 70% chance you’ll arrive no more than five minutes late. However, the exponential nature of the tail means —based on conditional probability— that if you have already had to wait for 35 minutes there’s about a 50-50 chance you will have to wait for another 35 minutes.</p> </div>]]></content:encoded>
    </item>
    <item>
      <title>“Cloud Numerics” Example: Analyzing Demographics Data from Windows Azure Marketplace</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-example-analyzing-demographics-data-from-windows-azure-marketplace</link>
      <pubDate>Tue, 07 Feb 2012 06:03:25 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/02/07/cloud-numerics-example-analyzing-demographics-data-from-windows-azure-marketplace/</guid>
      <description><![CDATA[Imagine your sales business is ‘booming’ in cities X, Y, and Z, and you are looking to expand. Given...]]></description>
      <content:encoded><![CDATA[<p class="ExternalClass82E40A08BA9C4AF5853209C15DD7E1A1">Imagine your sales business is ‘booming’ in cities X, Y, and Z, and you are looking to expand. Given that demographics provide regional indicators of sales potential, how do you find other cities with similar demographics? How do you sift though large sets of data to identify new cities and new expansion opportunities? </p>  <p class="ExternalClass3765C37D49A5457EBC029D0CDE4B1F48">In this application example, we use “Cloud Numerics” to analyze demographics data such as average household size and median age between different postal (ZIP) codes in the United States. </p>  <p class="ExternalClass3765C37D49A5457EBC029D0CDE4B1F48">This blog post demonstrates the following process for analyzing demographics data:</p>  <div class="ExternalClass3765C37D49A5457EBC029D0CDE4B1F48">   <ol>     <li>We go through the steps of subscribing to the dataset in the <a href="https://datamarket.azure.com/" target="_blank">Windows Azure Marketplace</a>. </li>      <li>We create a Cloud Numerics C# application for reading in data and computing correlation between different ZIP codes. We partition the application into two projects: one for reading in the data, and another one for performing the computation. </li>      <li>Finally, we step through the writing of results to Windows Azure blob storage. </li>   </ol> </div>  <h2>&#160;</h2>  <h2>Before You Begin</h2>  <div class="ExternalClass82E40A08BA9C4AF5853209C15DD7E1A1">   <ul>     <li>Create a Windows Live ID for accessing Windows Azure Marketplace </li>      <li>Create a Windows Azure subscription for deploying and running the application (if do not have one already) </li>      <li><a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_install_cloud_numerics">Install “Cloud Numerics”</a> on your local computer where you develop your C# applications </li>      <li>Run the example application as detailed in the “Cloud Numerics” Lab <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_run_a_distributed_application_over_azure">Getting Started</a> wiki page to validate your installation </li>   </ul> </div>  <p>Because of the memory usage, do not attempt to run this application on your local development machine. Additionally, you will need to run it on at least two compute nodes on your Windows Azure cluster. </p>  <table border="0" cellspacing="0" cellpadding="2" width="467"><tbody>     <tr>       <td valign="bottom" width="465"><em><strong>Note!</strong></em></td>     </tr>      <tr>       <td valign="top" width="465">You specify how many compute nodes are allocated when you use the Cloud Numerics Deployment Utility to configure your Windows Azure cluster. For details, see <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx#_Ref310275063">this</a> section in the <a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx">Getting Started</a> guide.</td>     </tr>   </tbody></table>  <h2>&#160;</h2>  <h2>Step 1: Subscribe to the Demographics Dataset at Windows Azure Marketplace</h2>  <p>For this demonstration, we use the dataset “2010 Key US Demographics by ZIP Code, Place and County (Trial)” </p>  <p>To subscribe to the dataset:</p>  <ol>   <li>Sign up to Windows Azure Marketplace using your Windows Live ID at: <a class="auto-style1" title="https://datamarket.azure.com/" href="https://datamarket.azure.com/">https://datamarket.azure.com/</a> </li>    <li>Navigate to the page for the dataset: <a class="auto-style1" title="https://datamarket.azure.com/dataset/c7154924-7cab-47ac-97fb-7671376ff656" href="https://datamarket.azure.com/dataset/c7154924-7cab-47ac-97fb-7671376ff656">https://datamarket.azure.com/dataset/c7154924-7cab-47ac-97fb-7671376ff656</a> </li>    <li>Select <strong>Sign Up</strong>. Then click the <strong>Details</strong> tab of the dataset, and take note of the Service Root URI <a class="auto-style1" href="https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/">https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/</a> . This URI will be used in creating the service reference in the next step. </li>    <li>Finally, go to <strong>My Account</strong>, <strong>Account Keys</strong> and take note of the long Value string. You will need this string in the next step to access the dataset from the C# application. </li> </ol>  <h2>&#160;</h2>  <h2>Step 2: Set Up the Cloud Numerics Project</h2>  <p>To set up your Cloud Numerics Visual Studio project:</p>  <ol>   <li>Start Microsoft Visual Studio and create a solution from the Cloud Numerics project template. Let’s call the solution “CloudDemographics.” </li>    <li>Rename the “MSCloudNumerics” project with more descriptive language. For the purposes of this blog post, we will name it “Demographics.” </li>    <li>Next, add a new project to the solution as a C# class library. This project will have the code for reading data. let’s call the project “DemographicsReader.” </li> </ol>  <p>We now need to add project dependency from Demographics to DemographicsReader. </p>  <ol>   <li>In Solution Explorer, under the <strong>Demographics</strong> project, right-click <strong>References</strong> and select <strong>Add References</strong>. </li>    <li>Click the <strong>Projects</strong> tab, and browse and add <strong>DemographicsReader</strong> as a reference. </li>    <li>Also add a .NET reference for Microsoft.WindowsAzure.StorageClient. We’ll need it later on when it’s time to write results to blob storage. </li> </ol>  <p>Finally, go to the DemographicsReader project, and add references to the following managed assemblies. In the <strong>Add References</strong> window, click <strong>Browse</strong> and find the assemblies, typically found at C:\Program Files\Microsoft Numerics\v0.1\Bin</p>  <ul>   <li>Microsoft.Numerics.DenseArrays </li>    <li>Microsoft.Numerics.Distributed.IO </li>    <li>Microsoft.Numerics.DistributedDenseArrays </li>    <li>Microsoft.Numerics.ManagedArrayImpl </li>    <li>Microsoft.Numerics.Runtime </li>    <li>Microsoft.Numerics.TCDistArrayHandle </li> </ul>  <h2>&#160;</h2>  <h2>Step 3: Add Service Reference to Dataset</h2>  <p>To get data into the application, we need to add a service reference to the dataset. </p>  <ol style="margin: 0px">   <li>In Solution Explorer, right-click the DemographicsReader project and select Add Service Reference. </li>    <li>In the dialog window, enter <a href="https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/">https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/</a> as the address. Also, specify “USDemographics” as the namespace. Adding the reference provides auto-generated flexible query methods that reside in the DemographicsReader.USDemographics namespace and allow us to access the dataset. </li> </ol>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/2337.blogpost1_626286BE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/2337.blogpost1_5F00_626286BE.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="blogpost1" border="0" alt="blogpost1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/4810.blogpost1_thumb_3A4FD79F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/4810.blogpost1_5F00_thumb_5F00_3A4FD79F.png" width="289" height="404" /></a></p>  <table border="0" cellspacing="0" cellpadding="2" width="467"><tbody>     <tr>       <td valign="bottom" width="465"><em><strong>Note!</strong></em></td>     </tr>      <tr>       <td valign="top" width="465">For an example of how to use a flexible query, see the MSDN Library topic titled <a href="https://msdn.microsoft.com/en-us/library/gg312152.aspx">Create a Flexible Query Application</a>.</td>     </tr>   </tbody></table>  <p>&#160;</p>  <p>3.&#160; Add the following “using” statements to the DemographicsReader project’s Class1.cs file, and declare a namespace “DemographicsReader” that will contain the classes for accessing the demographics data.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:82698baf-096e-4a64-a138-d399708c904f" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 500px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">using</span> System;         <br /><span style="color: #0000ff">using</span> System.Collections.Generic;         <br /><span style="color: #0000ff">using</span> System.Linq;         <br /><span style="color: #0000ff">using</span> msnl = Microsoft.Numerics.Local;         <br /><span style="color: #0000ff">using</span> DemographicsReader.USDemographics;         <br /><span style="color: #0000ff">using</span> System.Net;         <br />        <br /><span style="color: #0000ff">namespace</span> DemographicsReader         <br />{         <br />        <br />}</div>   </div> </div>  <p></p>  <p>4.&#160; Add a class named&#160; “DemographicsReference” to this namespace with the following private members and a constructor.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8ad04e48-08f6-4b1d-92e5-560b38dec3a4" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">DemographicsReference</span>&lt;T&gt;         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #2b91af">Uri</span> serviceURI;         <br />&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #2b91af">EsriKeyUSDemographicsTrialContainer</span> context;         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> DemographicsReference()         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; serviceURI = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(<span style="color: #a31515">@&quot;https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; context = <span style="color: #0000ff">new</span> <span style="color: #2b91af">EsriKeyUSDemographicsTrialContainer</span>(serviceURI);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Change these to your Live ID and Azure Marketplace key</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Credentials = <span style="color: #0000ff">new</span> <span style="color: #2b91af">NetworkCredential</span>(<span style="color: #a31515">@&quot;myemail@live.com&quot;</span>,         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">@&quot;myAzureMarketplaceKey&quot;</span>);         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>  <p>&#160;</p>  <p>5.&#160; Replace &quot;myemail@live.com”&#160; with your Live ID and “myAzureMarketplaceKey” with the key from <a href="#_subscribe_to_the_demographics">Step 1</a>.</p>  <h2>Step 4: Create a Serial Reader for Windows Azure Marketplace Data </h2>  <p>Next, let’s build the LINQ query operation for reading in the data. A single transaction returns a maximum of 100 rows. However, we want to read in much more data. Therefore, we create a list where we append and consolidate the individual query results. We structure the query so that we can start from a given row, read in a block of rows, move forward, read in another block, and so forth. </p>  <p>The query, by default, returns objects of type <span style="color: #2b91af">demog1</span>. This is a class that holds the demographics data as fields. However, we want to be able to select an arbitrary subset of columns. We accomplished this by supplying <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, T&gt; selector function into the query as an argument. </p>  <p>Add the following method to the DemographicsReference&lt;T&gt; class</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:65355b87-480e-42df-8c13-869af2d6cf3c" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #008000">// Method to get demographics data</span>         <br /><span style="color: #0000ff">public</span> <span style="color: #2b91af">IList</span>&lt;T&gt; GetDemographicsData(<span style="color: #0000ff">int</span> startIndex, <span style="color: #0000ff">int</span> blocks, <span style="color: #0000ff">int</span> blockSize, <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, T&gt; selector)         <br />{         <br />&#160;&#160;&#160; <span style="color: #008000">// Read in blocks of data and append the results to a list&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160; <span style="color: #2b91af">List</span>&lt;T&gt; queryResult = <span style="color: #0000ff">new</span> <span style="color: #2b91af">List</span>&lt;T&gt;();         <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; blocks; i++)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Try reading each block few times in case reading fails&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> retries = 0;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> maxRetries = 10;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">bool</span> success = <span style="color: #0000ff">false</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">while</span> (success == <span style="color: #0000ff">false</span>)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">try</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Select only geographies that have ZIP codes&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Order the results by ZIP code to ensure consistent ordering&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Skip to specific starting index&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Finally select subset of members and convert to list&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; queryResult.AddRange(context.demog1.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Where(demographic =&gt; demographic.GeographyType == <span style="color: #a31515">&quot;ZIP Code&quot;</span>).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OrderBy(demographic =&gt; demographic.GeographyId).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Skip(startIndex + i * blockSize).Take(blockSize).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Select(selector).ToList());         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; success = <span style="color: #0000ff">true</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">catch</span> (<span style="color: #2b91af">Exception</span> ex)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Error: {0}&quot;</span>, ex.Message);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; retries++;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (retries &gt; maxRetries) { <span style="color: #0000ff">throw</span> ex; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> queryResult;         <br />}</div>   </div> </div>  <p>&#160;</p>  <table border="0" cellspacing="0" cellpadding="2" width="495"><tbody>     <tr>       <td valign="bottom" width="493"><em><strong>Note!</strong></em></td>     </tr>      <tr>       <td valign="top" width="493">To increase robustness, the method attempts to read in a block a few times in case the query fails initially.</td>     </tr>   </tbody></table>  <h2>&#160;</h2>  <h2>Step 5: Parallelize Reader Using IParallelReader Interface</h2>  <p>Now, we have the basic framework in place to read in data. Next, we implement the <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/18/cloud-numerics-example-using-the-iparallelreader-interface.aspx" target="_blank">Cloud Numerics IParallelReader</a> interface to read in the data to a distributed array in parallel fashion. </p>  <p>Add the following class “DemographicsData” to the DemographicsReader namespace.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9ab169b0-3c2c-434c-9b43-c27e685e6d4c" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px">[<span style="color: #2b91af">Serializable</span>]         <br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">DemographicsData</span> : Microsoft.Numerics.Distributed.IO.<span style="color: #2b91af">IParallelReader</span>&lt;<span style="color: #0000ff">double</span>&gt;         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> samples;         <br />&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> blockSize = 100; <span style="color: #008000">// Maximum number of rows from query is a block of 100 rows</span>         <br />        <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> DemographicsData(<span style="color: #0000ff">int</span> samples)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (samples % blockSize != 0)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> <span style="color: #2b91af">ArgumentException</span>(<span style="color: #a31515">&quot;Number of samples must be a multiple of &quot;</span> + <span style="color: #0000ff">this</span>.blockSize);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">this</span>.samples = samples;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Concatenate blocks of rows to form a distributed array</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> DistributedDimension         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> 0; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">set</span> { }         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Simple helper struct to keep track of block dimensions</span>         <br />&#160;&#160;&#160; [<span style="color: #2b91af">Serializable</span>]         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> <span style="color: #2b91af">BlockInfo</span>         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> startIndex;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> blocks;         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Attempt to divide blocks between ranks evenly</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #2b91af">Object</span>[] ComputeAssignment(<span style="color: #0000ff">int</span> ranks)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Object</span>[] blockInfo = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Object</span>[ranks];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">BlockInfo</span> thisBlockInfo;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocks = samples / blockSize;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocksPerRank = (<span style="color: #0000ff">int</span>)<span style="color: #2b91af">Math</span>.Ceiling((<span style="color: #0000ff">double</span>)blocks / (<span style="color: #0000ff">double</span>)ranks);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> remainingBlocks = blocks;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> startIndex = 0;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; ranks; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute block info</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; thisBlockInfo.startIndex = startIndex;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; thisBlockInfo.blocks = System.<span style="color: #2b91af">Math</span>.Max(System.<span style="color: #2b91af">Math</span>.Min(blocksPerRank, remainingBlocks),0);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; startIndex = startIndex + thisBlockInfo.blocks * blockSize;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; remainingBlocks = remainingBlocks - thisBlockInfo.blocks;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Assingn thisBlockInfo into blockInfo</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; blockInfo[i] = thisBlockInfo;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> blockInfo;         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Method that queries the data and converts results to numeric array</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> msnl.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; ReadWorker(<span style="color: #2b91af">Object</span> blockInfoAsObject)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographicsRef = <span style="color: #0000ff">new</span> <span style="color: #2b91af">DemographicsReference</span>&lt;<span style="color: #2b91af">demog1</span>&gt;();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Select all data from each row</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, <span style="color: #2b91af">demog1</span>&gt; selector = demographic =&gt; demographic;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Get information about blocks to read</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">BlockInfo</span> blockInfo = (<span style="color: #2b91af">BlockInfo</span>)blockInfoAsObject;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocks = blockInfo.blocks;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> startIndex = blockInfo.startIndex;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> columns = 10;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnl.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; data;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (blocks == 0)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808080">///</span><span style="color: #008000"> If number of blocks is 0 return empty array</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = msnl.<span style="color: #2b91af">NumericDenseArrayFactory</span>.Create&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { 0, columns });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">else</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Execute query</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> dmList = demographicsRef.GetDemographicsData(startIndex, blocks, blockSize, selector);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rows = dmList.Count();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = msnl.<span style="color: #2b91af">NumericDenseArrayFactory</span>.Zeros&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, columns });         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Copy a subset of data to array columns</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; rows; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 0] = (<span style="color: #0000ff">double</span>)dmList[i].AverageHouseholdSize2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 1] = (<span style="color: #0000ff">double</span>)dmList[i].HouseholdGrowth2010To2015Annual;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 2] = (<span style="color: #0000ff">double</span>)dmList[i].MedianAge2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 3] = (<span style="color: #0000ff">double</span>)dmList[i].MedianHomeValue2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 4] = (<span style="color: #0000ff">double</span>)dmList[i].PctBachelorsDegOrHigher2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 5] = (<span style="color: #0000ff">double</span>)dmList[i].PctOwnerOccupiedHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 6] = (<span style="color: #0000ff">double</span>)dmList[i].PctRenterOccupiedHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 7] = (<span style="color: #0000ff">double</span>)dmList[i].PctVacantHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 8] = (<span style="color: #0000ff">double</span>)dmList[i].PerCapitaIncome2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 9] = (<span style="color: #0000ff">double</span>)dmList[i].PerCapitaIncomeGrowth2010To2015Annual;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> data;         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>  <p>The class constructor expects the number of dataset rows (“samples”) as input. The method “ComputeAssignment” divides the total number of rows into groups (referred to here as “blocks”) and attempts to distribute these blocks evenly between ReadWorkers. The “ReadWorker” method is executed in parallel fashion: there is one parallel call in each rank. The method expects as input a start index and a specified number of blocks to read. For example, the first worker might read rows 0-999, the second one rows 1000-1999 and so on. Then, each ReadWorker converts the demographics indicators from the query results into array columns. The arrays from each ReadWorker are then concatenated to form a large distributed array.</p>  <p>See the blog post titled <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/18/cloud-numerics-example-using-the-iparallelreader-interface.aspx">“Cloud Numerics” Example: Using the IParallelReader Interface</a> for more details on how to use the IParallelReader interface. </p>  <h2>Step 6: Add Method for Getting Mapping from Rows to Geographies</h2>  <p>Because the resulting distributed array is all numeric, we need an auxiliary list to map array rows to geographies. We accomplish this by adding a serial reader named “GetRowMapping.” We also add a struct “ZipCodeAndLocation” that holds the ZIP Code, city name, and state as well as the row index. The GetRowMapping then returns a list of such structs.</p>  <p>1.&#160; First, add the following struct to the top-level of the DemographicsReader namespace</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bf2048e8-e059-45df-a221-0392c14672f6" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #008000">// A class to contain zip code and location information, as well as an index</span>         <br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">ZipCodeAndLocation</span>         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> _zipCode, _location, _state;         <br />&#160;&#160;&#160; <span style="color: #0000ff">int</span> _idx;         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> zipCode { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _zipCode; } }         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> location { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _location; } }         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> state { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _state; } }         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> idx         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _idx; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">set</span> { _idx = <span style="color: #0000ff">value</span>; }         <br />&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> ZipCodeAndLocation(<span style="color: #0000ff">string</span> zipCode, <span style="color: #0000ff">string</span> location, <span style="color: #0000ff">string</span> state)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _zipCode = zipCode;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _location = location;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _state = state;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _idx = 0;         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>  <p>&#160;</p>  <p>2.&#160; Next, add a method GetRowMapping to the DemographicsData class from the previous step.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cdc81edc-0ef7-45a6-a73f-106f9c97a0cb" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">public</span> <span style="color: #2b91af">IList</span>&lt;ZipCodeAndLocation&gt; GetRowMapping()         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographicsRef = <span style="color: #0000ff">new</span> DemographicsReference&lt;ZipCodeAndLocation&gt;();         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// select geography ID, name, state abbreviation and index</span>         <br />&#160;&#160;&#160; <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, ZipCodeAndLocation&gt; selector =         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; demographic =&gt; <span style="color: #0000ff">new</span> ZipCodeAndLocation(demographic.GeographyId, demographic.GeographyName, demographic.StateAbbreviation);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Execute the query</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowMapping = demographicsRef.GetDemographicsData(0, <span style="color: #0000ff">this</span>.samples / <span style="color: #0000ff">this</span>.blockSize, <span style="color: #0000ff">this</span>.blockSize, selector);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Construct mapping</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; rowMapping.Count; i++)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; rowMapping[i].idx = i;         <br />&#160;&#160;&#160; }         <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> rowMapping;         <br />}</div>   </div> </div>  <p>&#160;</p>  <p>Here we use a selector that only picks out the GeographyID (the ZIP code), GeographyName (the city name), and StateAbbreviation from the full query. Then, because the results are in the same sorted order as those from the earlier demographics query, we can use a simple for-loop to add an index.</p>  <h2>Step 7: Compute Correlation Matrix Using Distributed Data</h2>  <p>Next, we’ll move to the Demographics project. We add a static method that expects a distributed array as input, normalizes the rows and columns, and then computes a correlation matrix. The columns have to be normalized because otherwise they would be on vastly different scales: for comparing per capita income and median age, for example. We do this by subtracting the mean of each column, and dividing by the standard deviation. Note how the KroneckerProduct method is used to tile vectors into an array that matches the data array size. The rows are then normalized to obtain the correlation coefficients between –1 and 1.</p>  <p>To get the correlation matrix between all ZIP codes, we need to compute correlation coefficients between each pair of rows. An efficient way to perform this computation is to multiply the data with its own transpose. This operation is at the heart of the application. Because it produces a very large matrix (30000-by-30000), performing the computation on a distributed cluster yields benefits. </p>  <p>Delete the default template code from Demographics project source code, and add the following: </p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:28361263-f693-480b-9e7f-94164a7e27ca" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">using</span> System;         <br /><span style="color: #0000ff">using</span> System.Collections.Generic;         <br /><span style="color: #0000ff">using</span> System.Linq;         <br /><span style="color: #0000ff">using</span> System.Text;         <br /><span style="color: #0000ff">using</span> msnl = Microsoft.Numerics.Local;         <br /><span style="color: #0000ff">using</span> msnd = Microsoft.Numerics.Distributed;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.LinearAlgebra;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.Statistics;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.Mathematics;         <br /><span style="color: #0000ff">using</span> Microsoft.WindowsAzure;         <br /><span style="color: #0000ff">using</span> Microsoft.WindowsAzure.StorageClient;         <br /><span style="color: #0000ff">using</span> DemographicsReader;         <br />        <br />        <br /><span style="color: #0000ff">namespace</span> Demographics         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">Program</span>         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">static</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; Correlate(msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; data)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix</span>         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Helper vectors</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> rows = data.Shape[0];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> columns = data.Shape[1];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; columnOfOnes = <span style="color: #0000ff">new</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, 1 });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; columnOfOnes.Fill(1);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; rowOfOnes = <span style="color: #0000ff">new</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { 1, columns });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rowOfOnes.Fill(1);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Normalize each column to be between -1 and 1</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Subtract mean</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> columnMean = <span style="color: #2b91af">Descriptive</span>.Mean(data, 0);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data - <span style="color: #2b91af">Operations</span>.KroneckerProduct(columnOfOnes, columnMean);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Divide by standard deviation</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> columnStandardDeviation = <span style="color: #2b91af">BasicMath</span>.Sqrt(rows * <span style="color: #2b91af">Descriptive</span>.Mean(data * data, 0));         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data / <span style="color: #2b91af">Operations</span>.KroneckerProduct(columnOfOnes, columnStandardDeviation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Next normalize rows</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowMean = <span style="color: #2b91af">Descriptive</span>.Mean(data, 1);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data - <span style="color: #2b91af">Operations</span>.KroneckerProduct(rowMean, rowOfOnes);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowStandardDeviation = <span style="color: #2b91af">BasicMath</span>.Sqrt(columns * <span style="color: #2b91af">Descriptive</span>.Mean(data * data, 1));         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data / <span style="color: #2b91af">Operations</span>.KroneckerProduct(rowOfOnes, rowStandardDeviation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix by multiplying </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> correlationMatrix = <span style="color: #2b91af">Operations</span>.MatrixMultiply(data, data.Transpose());         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> correlationMatrix;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>  <p>In addition to the Correlate method, this code includes the necessary “using” statements for Cloud Numerics namespaces.</p>  <h2>Step 8: Select Interesting Subset of Cities and Write the Correlations into a Blob</h2>  <p>We store results to Windows Azure blob storage as a blob resembling a .csv formatted file. To save time and memory, we only write a small subset of the 30000-by-30000 correlation matrix to a blob. Add the following method to the Demographics Program class. Also, change “myAccountKey” and “myAccountName” to the key and name of your own storage account.This method takes a list of ZipCodeAndLocation objects we’re interested in, finds the corresponding rows and columns from the correlation matrix, and writes the results to a string. Then it creates a container “demographicsresult” and a blob, “demographicsresult.csv”, makes the blob publicly readable, and uploads the string to https://&lt;myAccountName&gt;.blob.core.net/demographicsresult/demographicsresult.csv .</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9531834f-4bac-4f0f-ae68-9843fc3c116a" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> WriteOutput(msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; corr, <span style="color: #0000ff">int</span>[] rowArray, <span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">ZipCodeAndLocation</span>&gt; rowLocation)         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> nRows = rowArray.Count();         <br />&#160;&#160;&#160; <span style="color: #2b91af">StringBuilder</span> output = <span style="color: #0000ff">new</span> <span style="color: #2b91af">StringBuilder</span>();         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Write header rows</span>         <br />&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot; , &quot;</span>);         <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, &quot;</span> + rowLocation[rowArray[i]].location);         <br />&#160;&#160;&#160; }         <br />&#160;&#160;&#160; output.AppendLine();         <br />        <br />&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot; , &quot;</span>);         <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, ZIP &quot;</span> + rowLocation[rowArray[i]].zipCode);         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Write rows</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.AppendLine();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(rowLocation[rowArray[i]].location + <span style="color: #a31515">&quot;, ZIP &quot;</span> + rowLocation[rowArray[i]].zipCode);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> j = 0; j &lt; nRows; j++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, &quot;</span> + corr[rowArray[i], rowArray[j]]);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Write to blob storage</span>         <br />&#160;&#160;&#160; <span style="color: #008000">// Replace &quot;myAccountKey&quot; and &quot;myAccountName&quot; by your own storage account key and name</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> accountKey = <span style="color: #a31515">&quot;myAccountKey&quot;</span>;         <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> accountName = <span style="color: #a31515">&quot;myAccountName&quot;</span>;         <br />&#160;&#160;&#160; <span style="color: #008000">// Result blob and container name</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> containerName = <span style="color: #a31515">&quot;demographicsresult&quot;</span>;         <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> blobName = <span style="color: #a31515">&quot;demographicsresult.csv&quot;</span>;         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Create result container and blob</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> storageAccountCredential = <span style="color: #0000ff">new</span> <span style="color: #2b91af">StorageCredentialsAccountAndKey</span>(accountName, accountKey);         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> storageAccount = <span style="color: #0000ff">new</span> <span style="color: #2b91af">CloudStorageAccount</span>(storageAccountCredential, <span style="color: #0000ff">true</span>);         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> blobClient = storageAccount.CreateCloudBlobClient();         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultContainer = blobClient.GetContainerReference(containerName);         <br />&#160;&#160;&#160; resultContainer.CreateIfNotExist();         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultBlob = resultContainer.GetBlobReference(blobName);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Make result blob publicly readable,</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultPermissions = <span style="color: #0000ff">new</span> <span style="color: #2b91af">BlobContainerPermissions</span>();         <br />&#160;&#160;&#160; resultPermissions.PublicAccess = <span style="color: #2b91af">BlobContainerPublicAccessType</span>.Blob;         <br />&#160;&#160;&#160; resultContainer.SetPermissions(resultPermissions);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Upload result to blob</span>         <br />&#160;&#160;&#160; resultBlob.UploadText(output.ToString());         <br />}</div>   </div> </div>  <p>&#160;</p>  <h2>Step 9: Putting it All Together</h2>  <p>Finally, we add a main method that instantiates the reader, reads in data, computes correlations, and selects the interesting subset of cities from the row mapping. For example, let’s select Cambridge, MA, Redmond, WA, and Palo Alto, CA. Add the following main method to the Demographics Program class. </p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4b813e60-6049-4e6b-9657-222e3a63fd15" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">static</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Main()         <br />{         <br />&#160;&#160;&#160; <span style="color: #008000">// Initialize distributed runtime</span>         <br />&#160;&#160;&#160; Microsoft.Numerics.<span style="color: #2b91af">NumericsRuntime</span>.Initialize();         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Read in demographics data from Azure marketplace for different ZIP codes</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographics = <span style="color: #0000ff">new</span> <span style="color: #2b91af">DemographicsData</span>(30000);         <br />        <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> data = Microsoft.Numerics.Distributed.IO.<span style="color: #2b91af">Loader</span>.LoadData&lt;<span style="color: #0000ff">double</span>&gt;(demographics);         <br />        <br />&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Got {0} rows&quot;</span>, data.Shape[0]);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix</span>         <br />&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Computing correlation matrix&quot;</span>);         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> corr = Correlate(data);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">//Get mapping between ZIP codes, city names and matrix rows</span>         <br />&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Selecting rows&quot;</span>);         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowLocation = demographics.GetRowMapping();         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Select some pairs of cities to demostrate result</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowSelection = rowLocation.Where(row =&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Cambridge&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;MA&quot;</span> ) ||         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Redmond&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;WA&quot;</span> )||         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Palo Alto&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;CA&quot;</span> )).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Select(row =&gt; row.idx).ToArray();         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Write output</span>         <br />&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Writing output&quot;</span>);         <br />&#160;&#160;&#160; WriteOutput(corr, rowSelection, rowLocation);         <br />        <br />&#160;&#160;&#160; <span style="color: #008000">// Shut down runtime</span>         <br />&#160;&#160;&#160; Microsoft.Numerics.<span style="color: #2b91af">NumericsRuntime</span>.Shutdown();         <br />}</div>   </div> </div>  <p>Now, the application is ready to be deployed. Set AppConfigure as StartUp project, build and deploy using the Deployment Utility. The application will run for a few minutes. The results can be viewed, for example by opening https://&lt;myAccountName&gt;.blob.core.net/demographicsresult/demographicsresult.csv as a spreadsheet</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/6064.blogpost2_6E17CDF0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/6064.blogpost2_5F00_6E17CDF0.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="blogpost2" border="0" alt="blogpost2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/7041.blogpost2_thumb_3277BF30.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/7041.blogpost2_5F00_thumb_5F00_3277BF30.png" width="504" height="131" /></a></p>  <p>Here the correlation coefficients above 0.9 between different ZIP codes are highlighted.</p>  <h2>Source Code</h2>  <p>For your convenience, this section of the blog post contains the entire source code for you to copy. Remember to change the “myAccountKey” and “myAccountName” strings to your storage account key and name, and change “myemail@live.com” and “myAzureMarketplaceKey” to your Live ID and key from Step 1.</p>  <h3>Demographics Program.cs</h3>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:203aac31-74b5-438f-886d-e6a2c484bab8" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">using</span> System;         <br /><span style="color: #0000ff">using</span> System.Collections.Generic;         <br /><span style="color: #0000ff">using</span> System.Linq;         <br /><span style="color: #0000ff">using</span> System.Text;         <br /><span style="color: #0000ff">using</span> msnl = Microsoft.Numerics.Local;         <br /><span style="color: #0000ff">using</span> msnd = Microsoft.Numerics.Distributed;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.LinearAlgebra;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.Statistics;         <br /><span style="color: #0000ff">using</span> Microsoft.Numerics.Mathematics;         <br /><span style="color: #0000ff">using</span> Microsoft.WindowsAzure;         <br /><span style="color: #0000ff">using</span> Microsoft.WindowsAzure.StorageClient;         <br /><span style="color: #0000ff">using</span> DemographicsReader;         <br />        <br />        <br /><span style="color: #0000ff">namespace</span> Demographics         <br />{         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">Program</span>         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">static</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; Correlate(msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; data)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix</span>         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Helper vectors</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> rows = data.Shape[0];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> columns = data.Shape[1];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; columnOfOnes = <span style="color: #0000ff">new</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, 1 });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; columnOfOnes.Fill(1);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; rowOfOnes = <span style="color: #0000ff">new</span> msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { 1, columns });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rowOfOnes.Fill(1);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Normalize each column to be between -1 and 1</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Subtract mean</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> columnMean = <span style="color: #2b91af">Descriptive</span>.Mean(data, 0);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data - <span style="color: #2b91af">Operations</span>.KroneckerProduct(columnOfOnes, columnMean);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Divide by standard deviation</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> columnStandardDeviation = <span style="color: #2b91af">BasicMath</span>.Sqrt(rows * <span style="color: #2b91af">Descriptive</span>.Mean(data * data, 0));         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data / <span style="color: #2b91af">Operations</span>.KroneckerProduct(columnOfOnes, columnStandardDeviation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Next normalize rows</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowMean = <span style="color: #2b91af">Descriptive</span>.Mean(data, 1);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data - <span style="color: #2b91af">Operations</span>.KroneckerProduct(rowMean, rowOfOnes);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowStandardDeviation = <span style="color: #2b91af">BasicMath</span>.Sqrt(columns * <span style="color: #2b91af">Descriptive</span>.Mean(data * data, 1));         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = data / <span style="color: #2b91af">Operations</span>.KroneckerProduct(rowOfOnes, rowStandardDeviation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix by multiplying </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> correlationMatrix = <span style="color: #2b91af">Operations</span>.MatrixMultiply(data, data.Transpose());         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> correlationMatrix;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Output writer method</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> WriteOutput(msnd.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; corr, <span style="color: #0000ff">int</span>[] rowArray, <span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">ZipCodeAndLocation</span>&gt; rowLocation)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> nRows = rowArray.Count();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">StringBuilder</span> output = <span style="color: #0000ff">new</span> <span style="color: #2b91af">StringBuilder</span>();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Write header rows</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot; , &quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, &quot;</span> + rowLocation[rowArray[i]].location);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.AppendLine();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot; , &quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, ZIP &quot;</span> + rowLocation[rowArray[i]].zipCode);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Write rows</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nRows; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.AppendLine();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(rowLocation[rowArray[i]].location + <span style="color: #a31515">&quot;, ZIP &quot;</span> + rowLocation[rowArray[i]].zipCode);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> j = 0; j &lt; nRows; j++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; output.Append(<span style="color: #a31515">&quot;, &quot;</span> + corr[rowArray[i], rowArray[j]]);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Write to blob storage</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Replace &quot;myAccountKey&quot; and &quot;myAccountName&quot; by your own storage account key and name</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">string</span> accountKey = <span style="color: #a31515">&quot;myAccountKey&quot;</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">string</span> accountName = <span style="color: #a31515">&quot;myAccountName&quot;</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Result blob and container name</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">string</span> containerName = <span style="color: #a31515">&quot;demographicsresult&quot;</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">string</span> blobName = <span style="color: #a31515">&quot;demographicsresult.csv&quot;</span>;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Create result container and blob</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> storageAccountCredential = <span style="color: #0000ff">new</span> <span style="color: #2b91af">StorageCredentialsAccountAndKey</span>(accountName, accountKey);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> storageAccount = <span style="color: #0000ff">new</span> <span style="color: #2b91af">CloudStorageAccount</span>(storageAccountCredential, <span style="color: #0000ff">true</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> blobClient = storageAccount.CreateCloudBlobClient();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultContainer = blobClient.GetContainerReference(containerName);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resultContainer.CreateIfNotExist();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultBlob = resultContainer.GetBlobReference(blobName);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Make result blob publicly readable,</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> resultPermissions = <span style="color: #0000ff">new</span> <span style="color: #2b91af">BlobContainerPermissions</span>();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resultPermissions.PublicAccess = <span style="color: #2b91af">BlobContainerPublicAccessType</span>.Blob;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resultContainer.SetPermissions(resultPermissions);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Upload result to blob</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resultBlob.UploadText(output.ToString());         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">static</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Main()         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Initialize distributed runtime</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft.Numerics.<span style="color: #2b91af">NumericsRuntime</span>.Initialize();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Read in demographics data from Azure marketplace for different ZIP codes</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographics = <span style="color: #0000ff">new</span> <span style="color: #2b91af">DemographicsData</span>(30000);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> data = Microsoft.Numerics.Distributed.IO.<span style="color: #2b91af">Loader</span>.LoadData&lt;<span style="color: #0000ff">double</span>&gt;(demographics);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Got {0} rows&quot;</span>, data.Shape[0]);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute correlation matrix</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Computing correlation matrix&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> corr = Correlate(data);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">//Get mapping between ZIP codes, city names and matrix rows</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Selecting rows&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowLocation = demographics.GetRowMapping();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Select some pairs of cities to demostrate result</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowSelection = rowLocation.Where(row =&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Cambridge&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;MA&quot;</span>) ||         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Redmond&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;WA&quot;</span>) ||         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (row.location == <span style="color: #a31515">&quot;Palo Alto&quot;</span> &amp;&amp; row.state == <span style="color: #a31515">&quot;CA&quot;</span>)).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Select(row =&gt; row.idx).ToArray();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Write output</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Writing output&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WriteOutput(corr, rowSelection, rowLocation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Shut down runtime</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft.Numerics.<span style="color: #2b91af">NumericsRuntime</span>.Shutdown();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>  <h3>DemographicsReader Class1.cs</h3>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d927a284-1ad9-4510-9a90-3ed310d0cd77" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;Courier New&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 500px; overflow: auto; padding-top: 2px"><span style="color: #0000ff">using</span> System;         <br /><span style="color: #0000ff">using</span> System.Collections.Generic;         <br /><span style="color: #0000ff">using</span> System.Linq;         <br /><span style="color: #0000ff">using</span> msnl = Microsoft.Numerics.Local;         <br /><span style="color: #0000ff">using</span> DemographicsReader.USDemographics;         <br /><span style="color: #0000ff">using</span> System.Net;         <br />        <br /><span style="color: #0000ff">namespace</span> DemographicsReader         <br />{         <br />&#160;&#160;&#160; <span style="color: #008000">// A class to contain zip code and location information, as well as an index</span>         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">ZipCodeAndLocation</span>         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">string</span> _zipCode, _location, _state;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> _idx;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> zipCode { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _zipCode; } }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> location { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _location; } }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> state { <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _state; } }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> idx         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _idx; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">set</span> { _idx = <span style="color: #0000ff">value</span>; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> ZipCodeAndLocation(<span style="color: #0000ff">string</span> zipCode, <span style="color: #0000ff">string</span> location, <span style="color: #0000ff">string</span> state)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _zipCode = zipCode;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _location = location;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _state = state;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _idx = 0;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">DemographicsReference</span>&lt;T&gt;         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #2b91af">Uri</span> serviceURI;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #2b91af">EsriKeyUSDemographicsTrialContainer</span> context;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> DemographicsReference()         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; serviceURI = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(<span style="color: #a31515">@&quot;https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context = <span style="color: #0000ff">new</span> <span style="color: #2b91af">EsriKeyUSDemographicsTrialContainer</span>(serviceURI);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Change these to your Live ID and Azure Marketplace key</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Credentials = <span style="color: #0000ff">new</span> <span style="color: #2b91af">NetworkCredential</span>(<span style="color: #a31515">@&quot;myemail@live.com&quot;</span>,         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">@&quot;myAzureMarketplaceKey&quot;</span>);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Method to get demographics data</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #2b91af">IList</span>&lt;T&gt; GetDemographicsData(<span style="color: #0000ff">int</span> startIndex, <span style="color: #0000ff">int</span> blocks, <span style="color: #0000ff">int</span> blockSize, <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, T&gt; selector)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Read in blocks of data and append the results to a list&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">List</span>&lt;T&gt; queryResult = <span style="color: #0000ff">new</span> <span style="color: #2b91af">List</span>&lt;T&gt;();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; blocks; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Try reading each block few times in case reading fails&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> retries = 0;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> maxRetries = 10;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">bool</span> success = <span style="color: #0000ff">false</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">while</span> (success == <span style="color: #0000ff">false</span>)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">try</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Select only geographies that have ZIP codes&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Order the results by ZIP code to ensure consistent ordering&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Skip to specific starting index&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Finally select subset of members and convert to list&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; queryResult.AddRange(context.demog1.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Where(demographic =&gt; demographic.GeographyType == <span style="color: #a31515">&quot;ZIP Code&quot;</span>).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OrderBy(demographic =&gt; demographic.GeographyId).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Skip(startIndex + i * blockSize).Take(blockSize).         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Select(selector).ToList());         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; success = <span style="color: #0000ff">true</span>;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">catch</span> (<span style="color: #2b91af">Exception</span> ex)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Error: {0}&quot;</span>, ex.Message);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; retries++;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (retries &gt; maxRetries) { <span style="color: #0000ff">throw</span> ex; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> queryResult;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160; [<span style="color: #2b91af">Serializable</span>]         <br />&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">DemographicsData</span> : Microsoft.Numerics.Distributed.IO.<span style="color: #2b91af">IParallelReader</span>&lt;<span style="color: #0000ff">double</span>&gt;         <br />&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> samples;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> blockSize = 100; <span style="color: #008000">// Maximum number of rows from query is a block of 100 rows</span>         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> DemographicsData(<span style="color: #0000ff">int</span> samples)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (samples % blockSize != 0)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> <span style="color: #2b91af">ArgumentException</span>(<span style="color: #a31515">&quot;Number of samples must be a multiple of &quot;</span> + <span style="color: #0000ff">this</span>.blockSize);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">this</span>.samples = samples;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Concatenate blocks of rows to form a distributed array</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> DistributedDimension         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> 0; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">set</span> { }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Simple helper struct to keep track of block dimensions</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Serializable</span>]         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> <span style="color: #2b91af">BlockInfo</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> startIndex;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> blocks;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Attempt to divide blocks between ranks evenly</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #2b91af">Object</span>[] ComputeAssignment(<span style="color: #0000ff">int</span> ranks)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Object</span>[] blockInfo = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Object</span>[ranks];         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">BlockInfo</span> thisBlockInfo;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocks = samples / blockSize;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocksPerRank = (<span style="color: #0000ff">int</span>)<span style="color: #2b91af">Math</span>.Ceiling((<span style="color: #0000ff">double</span>)blocks / (<span style="color: #0000ff">double</span>)ranks);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> remainingBlocks = blocks;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> startIndex = 0;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; ranks; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Compute block info</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; thisBlockInfo.startIndex = startIndex;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; thisBlockInfo.blocks = System.<span style="color: #2b91af">Math</span>.Max(System.<span style="color: #2b91af">Math</span>.Min(blocksPerRank, remainingBlocks),0);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; startIndex = startIndex + thisBlockInfo.blocks * blockSize;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; remainingBlocks = remainingBlocks - thisBlockInfo.blocks;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Assingn thisBlockInfo into blockInfo</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; blockInfo[i] = thisBlockInfo;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> blockInfo;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Method that queries the data and converts results to numeric array</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> msnl.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; ReadWorker(<span style="color: #2b91af">Object</span> blockInfoAsObject)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographicsRef = <span style="color: #0000ff">new</span> <span style="color: #2b91af">DemographicsReference</span>&lt;<span style="color: #2b91af">demog1</span>&gt;();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Select all data from each row</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, <span style="color: #2b91af">demog1</span>&gt; selector = demographic =&gt; demographic;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Get information about blocks to read</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">BlockInfo</span> blockInfo = (<span style="color: #2b91af">BlockInfo</span>)blockInfoAsObject;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> blocks = blockInfo.blocks;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">int</span> startIndex = blockInfo.startIndex;         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">long</span> columns = 10;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msnl.<span style="color: #2b91af">NumericDenseArray</span>&lt;<span style="color: #0000ff">double</span>&gt; data;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (blocks == 0)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808080">///</span><span style="color: #008000"> If number of blocks is 0 return empty array</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = msnl.<span style="color: #2b91af">NumericDenseArrayFactory</span>.Create&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { 0, columns });         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">else</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Execute query</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> dmList = demographicsRef.GetDemographicsData(startIndex, blocks, blockSize, selector);         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rows = dmList.Count();         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data = msnl.<span style="color: #2b91af">NumericDenseArrayFactory</span>.Zeros&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, columns });         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Copy a subset of data to array columns</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; rows; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 0] = (<span style="color: #0000ff">double</span>)dmList[i].AverageHouseholdSize2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 1] = (<span style="color: #0000ff">double</span>)dmList[i].HouseholdGrowth2010To2015Annual;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 2] = (<span style="color: #0000ff">double</span>)dmList[i].MedianAge2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 3] = (<span style="color: #0000ff">double</span>)dmList[i].MedianHomeValue2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 4] = (<span style="color: #0000ff">double</span>)dmList[i].PctBachelorsDegOrHigher2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 5] = (<span style="color: #0000ff">double</span>)dmList[i].PctOwnerOccupiedHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 6] = (<span style="color: #0000ff">double</span>)dmList[i].PctRenterOccupiedHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 7] = (<span style="color: #0000ff">double</span>)dmList[i].PctVacantHousing2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 8] = (<span style="color: #0000ff">double</span>)dmList[i].PerCapitaIncome2010;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data[i, 9] = (<span style="color: #0000ff">double</span>)dmList[i].PerCapitaIncomeGrowth2010To2015Annual;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> data;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Serial method to query the data to get a mapping from array rows to geographies</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">ZipCodeAndLocation</span>&gt; GetRowMapping()         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> demographicsRef = <span style="color: #0000ff">new</span> <span style="color: #2b91af">DemographicsReference</span>&lt;<span style="color: #2b91af">ZipCodeAndLocation</span>&gt;();         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// select geography ID, name, state abbreviation and index</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">demog1</span>, <span style="color: #2b91af">ZipCodeAndLocation</span>&gt; selector =         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; demographic =&gt; <span style="color: #0000ff">new</span> <span style="color: #2b91af">ZipCodeAndLocation</span>(demographic.GeographyId, demographic.GeographyName, demographic.StateAbbreviation);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Execute the query</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">var</span> rowMapping = demographicsRef.GetDemographicsData(0, <span style="color: #0000ff">this</span>.samples / <span style="color: #0000ff">this</span>.blockSize, <span style="color: #0000ff">this</span>.blockSize, selector);         <br />        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// Construct mapping</span>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; rowMapping.Count; i++)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rowMapping[i].idx = i;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">return</span> rowMapping;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br />&#160;&#160;&#160; }         <br />}</div>   </div> </div>]]></content:encoded>
    </item>
    <item>
      <title>FAQs, Best Practices, Issues and Workarounds</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/faqs-best-practices-issues-and-workarounds</link>
      <pubDate>Mon, 06 Feb 2012 13:04:43 GMT</pubDate>
      <dc:creator><![CDATA[R Gray - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/02/06/faqs-best-practices-issues-and-workarounds/</guid>
      <description><![CDATA[&#160;  Frequently Asked Questions              Can I Use “Cloud Numerics” with F#?...]]></description>
      <content:encoded><![CDATA[<h1></h1>  <h1></h1>  <h1></h1>  <h2>&#160;</h2>  <h4><strong>Frequently Asked Questions</strong></h4>  <table border="0" cellspacing="0" cellpadding="2" width="449"><tbody>     <tr>       <td valign="top" width="447"><a href="#_can_I_use_cloud_numerics_with_Fsharp">Can I Use “Cloud Numerics” with F#?</a></td>     </tr>      <tr>       <td valign="top" width="447"><a href="#_Using_Multiple_Applications_on_the_Same_Azure_Storage_Account">Can Multiple Cloud Numerics Applications Use the Same Azure Storage Account?</a></td>     </tr>      <tr>       <td valign="top" width="447"><a href="#_Can_I_Share_an_Existing_Cloud Numerics_Solution_with_Another_User">Can I Share an Existing “Cloud Numerics” Solution with Another User?</a></td>     </tr>   </tbody></table>  <h4><strong>Best Practices</strong></h4>  <table border="0" cellspacing="0" cellpadding="2" width="400"><tbody>     <tr>       <td valign="top" width="398"><a href="#_Memory_Usage_and_Matrix_Size_Guidelines">Memory Usage and Matrix Size Guidelines</a></td>     </tr>      <tr>       <td valign="top" width="398"><a href="#_Partition_the_Use_of_Memory_Resources_in_Your_Program_with_using">Partition the Use of Memory Resources in Your Program with using{}</a></td>     </tr>   </tbody></table>  <h1></h1>  <h4>Known Issues</h4>  <table border="0" cellspacing="0" cellpadding="2" width="445"><tbody>     <tr>       <td valign="top" width="443"><a href="#_Transport_Level_Error_When_Receiving_Results_from_the_Server">Transport-Level Error When Receiving Results from the Server</a> </td>     </tr>      <tr>       <td valign="top" width="443"><a href="#_Superseded_Software_Packages_Not_Removed_Before_You_Install_the_Prerequisites">Superseded Software Packages Not Removed Before You Install the Prerequisites</a> </td>     </tr>      <tr>       <td valign="top" width="443"><a href="#_Network_Error_when_Creating_SQL_Server_Instance">Network Error when Creating SQL Server Instance</a></td>     </tr>      <tr>       <td valign="top" width="443"><a href="#_Cannot_Establish_Connection_with_SQL_Server">Cannot Establish Connection with SQL Server</a></td>     </tr>      <tr>       <td valign="top" width="443"><a href="#_Windows_Azure_Management_Service_Reports_a_Conflict">Windows Azure Management Service has Reported a Conflict</a></td>     </tr>   </tbody></table>  <h1></h1>  <h1>Frequently Asked Questions (FAQs)</h1>  <h2><a name="_can_I_use_cloud_numerics_with_Fsharp">Can I Use “Cloud Numerics” Libraries and Runtime with F#?</a></h2>  <p>Yes. See the blog post titled <a href="https://blogs.msdn.com/b/cloudnumerics/archive/2012/01/16/cloud-numerics-example-distributed-numerics-on-azure-with-f.aspx">“Cloud Numerics” Example: Distributed Numerics on Azure with F#</a>.</p>  <h2><a name="_Using_Multiple_Applications_on_the_Same_Azure_Storage_Account">Can Multiple Applications Use the Same Windows Azure Storage Account?</a></h2>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Yes, but you need to ensure that these applications have distinct project names, otherwise, each will overwrite the other application’s output. The post build event of a Microsoft codename “Cloud Numerics” C# project uses the project name to create an Azure blob. Identical project names using the same Windows Azure storage account will map application output to the same blob. </p>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">If multiple users use the same Windows Azure storage account while creating “Cloud Numerics” applications for Azure by way of the “Cloud Numerics” Deployment Utility, the applications must use different project names. </p>  <h2><a name="_Can_I_Share_an_Existing_Cloud Numerics_Solution_with_Another_User">Can I Share an Existing “Cloud Numerics” Solution with Another User?</a></h2>  <p>To share your “Cloud Numerics” Visual Studio solution with another user, a small modification must be made to the solution’s properties in order for the other user to execute the compiled solution locally. The reason for this is that the solution has fully-qualified paths in its application properties, and these paths reflect the directory structure of the development machine where the application was originally developed. For example, the following screen shows fully-qualified directory paths that descend into a user’s home directory.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/8078.image_50F25804.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/8078.image_5F00_50F25804.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/4784.image_thumb_760FA270.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/4784.image_5F00_thumb_5F00_760FA270.png" width="539" height="283" /></a></p>  <p>To change these path specifications so that a different user can run the compiled solution locally on a different machine, follow these steps.</p>  <table border="0" cellspacing="0" cellpadding="2" width="539"><tbody>     <tr>       <td valign="bottom" width="537"><strong><em><font color="#000000">Note!</font></em></strong></td>     </tr>      <tr>       <td valign="top" width="537">         <p>Applications submitted to be run on Windows Azure can be shared without this modification.</p>       </td>     </tr>   </tbody></table>  <p>To change the Start Option paths to reflect your local machine: </p>  <ol>   <li>From Solution Explorer, right-click the <strong>MSCloudNumericsApp</strong> and select <strong>Properties</strong>. </li>    <li>Click the <strong>Debug</strong> tab. </li>    <li>In the <strong>Start Options</strong> section of the <strong>Debug</strong> tab, edit the following fields to reflect the paths on your local development machine: </li> </ol>  <blockquote>   <p><strong>a.</strong>&#160; For the <strong>Command line arguments</strong> field, change the path to reflect the directory on the current machine where the “Cloud Numerics” Projects directory can be found. </p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/2318.image_42D36907.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/2318.image_5F00_42D36907.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/2627.image_thumb_3B47F99A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/2627.image_5F00_thumb_5F00_3B47F99A.png" width="340" height="82" /></a></p>    <p>For example, given the figure above, you would change:&#160; <br />&#160;&#160;&#160;&#160; c:\users\roastala\documents\visual studio 2010\Projects… </p>    <p>&#160;&#160;&#160;&#160; to:&#160; <br />&#160;&#160;&#160;&#160; c:\users\&lt;YourUsername&gt;\documents\visual studio 2010\Projects…<strong> </strong></p>    <p><strong>b.&#160; </strong>For the <strong>Working directory</strong> field, change the path to reflect the directory on the current machine where the “Cloud Numerics” Projects directory can be found. </p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/6835.image_5A8AA06D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/6835.image_5F00_5A8AA06D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/4774.image_thumb_613DA9F0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/4774.image_5F00_thumb_5F00_613DA9F0.png" width="307" height="32" /></a></p>    <p>For example, given the figure above, you would change: </p>    <p>&#160;&#160;&#160;&#160; c:\users\roastala\documents\… </p>    <p>&#160;&#160;&#160;&#160; to:      <br />&#160;&#160;&#160;&#160; c:\users\&lt;YourUsername&gt;\documents\…</p>    <p>&#160;&#160;&#160;&#160; --Where c:\users\&lt;YourUsername&gt;\ reflects the home directory of the user on the local development machine where you put the “Cloud Numerics” project. </p> </blockquote>  <p>&#160;&#160;&#160;&#160;&#160; 4.&#160;&#160; Change the Project Configuration from <strong>Debug</strong> to <strong>Release</strong>, and repeat the changes for the Release configuration.</p>  <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/6428.release_72AE0AC8.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/6428.release_5F00_72AE0AC8.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="release" border="0" alt="release" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/3276.release_thumb_46910DD7.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/3276.release_5F00_thumb_5F00_46910DD7.jpg" width="489" height="65" /></a></p>  <h1>Best Practices</h1>  <h2><a name="_Memory_Usage_and_Matrix_Size_Guidelines">Memory Usage and Matrix Size Guidelines</a></h2>  <p>The recommended maximum memory usage is &lt;=30% of physical memory. For a Windows Azure node used by a “Cloud Numerics” job, this equals roughly 4GB per node. All active variables in your application should not consume more than 30% of the physical memory available on the cluster. By default, the “Cloud Numerics” Deployment Utility creates clusters with extra-large Windows Azure nodes (8 cores, 14 GB memory).</p>  <h2><a name="_Partition_the_Use_of_Memory_Resources_in_Your_Program_with_using">Partition the Use of Memory Resources in Your Program with using{}</a></h2>  <p>For improved performance, you can evaluate any memory intensive array operation such as matrix creation and cloning, matrix multiplication, LU decomposition, or SVD decomposition within the C# using{} construct. This construct forces the de-allocation of memory from the managed heap when the program leaves the scope of execution bounded by the using{}. If you do not exercise using{} or similar constructs to free unused allocated memory, your cluster can run with noticeable latency and long processing times. </p>  <h1>Possible Issues and Suggested Workarounds</h1>  <h1></h1>  <h2><a name="_Transport_Level_Error_When_Receiving_Results_from_the_Server">Transport-Level Error When Receiving Results from the Server</a></h2>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">If you see the following error when interacting with SQL Azure, shut down all connections with SQL Azure, wait 10 to 20 minutes, and attempt your transaction again.</p>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">“A transport-level error has occurred when receiving results from the server (provider: TCP Provider, error:0. An existing connection was forcibly closed by the remote host.”</p>  <h2><a name="_Superseded_Software_Packages_Not_Removed_Before_You_Install_the_Prerequisites">Superseded Software Packages Not Removed Before You Install the Prerequisites</a></h2>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">The software packages referred to in this section must be uninstalled before you install the software prerequisites.</p>  <p class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">If you have any of the following software packages on your development machine, you need to uninstall them before you install the software prerequisites:</p>  <ul>   <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Microsoft HPC Pack 2008 R2 Azure Edition </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Microsoft HPC Pack 2008 R2 Client Components </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Microsoft HPC Pack 2008 R2 MS-MPI Redistributable Pack </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Microsoft HPC Pack 2008 R2 SDK </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Windows Azure SDK v1.5 </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Windows Azure AppFabric v1.5 </div>   </li>    <li>     <div class="ExternalClassBE46EDD862C54F27B79A4E73234CFE10">Windows Azure Tools for Microsoft VS2010 1.5 </div>   </li> </ul>  <h2><a name="_Network_Error_when_Creating_SQL_Server_Instance">Network Error when Creating SQL Server Instance</a></h2>  <p>When you deploy “Cloud Numerics,” for the first time, if you receive an error message when the “Cloud Numerics” Deployment Utility attempts to create your SQL Azure database, it is likely your network rules are blocking SSL traffic on TCP port 8443. In order to create the SQL Azure server instance, the “Cloud Numerics” Deployment Utility makes a network call to the SQL Azure Management API over this port.</p>  <p>To allow the deployment tool to complete the cluster deployment sequence, your site’s firewall rules need to enable SSL traffic over port 8443. The location where this modification needs to be made depends on your network route to SQL Azure. It may involve updating firewall rules on your local machine (where you run the deployment utility) and possibly any proxy or gateway servers through which traffic is filtered.</p>  <p>For details regarding requests sent to the SQL Azure Management API, see the following URL:</p>  <p><a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg715281.aspx">https://msdn.microsoft.com/en-us/library/windowsazure/gg715281.aspx</a></p>  <h2><a name="_Cannot_Establish_Connection_with_SQL_Server">Cannot Establish Connection with SQL Server</a></h2>  <p>Depending on your site IT policy, you might need a gateway client in order to set up a connection with the Azure Storage service. </p>  <p><a href="https://www.microsoft.com/en-us/server-cloud/forefront/threat-management-gateway-trial.aspx">https://www.microsoft.com/en-us/server-cloud/forefront/threat-management-gateway-trial.aspx</a></p>  <p>If you see the following message, it is typically a indicator that you need to install a gateway client.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/8407.image_65D3B4AA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/8407.image_5F00_65D3B4AA.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/7180.image_thumb_44E04203.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/7180.image_5F00_thumb_5F00_44E04203.png" width="464" height="244" /></a></p>  <h2><a name="_Windows_Azure_Management_Service_Reports_a_Conflict">Windows Azure Management Service Reports a Conflict</a></h2>  <p>The management service reports a conflict if you attempt to deploy your cluster with a service name that is already in use. </p>  <p>If you see the following message when you try to deploy a “Cloud Numerics” application using the “Cloud Numerics” Deployment Utility (AppConfigure.exe), this can be&#160; an indicator that the Windows Azure service name you chose is already in use.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/1401.duplicateDnsHostname_7239A795.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/1401.duplicateDnsHostname_5F00_7239A795.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="duplicateDnsHostname" border="0" alt="duplicateDnsHostname" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/10/metablogapi/8741.duplicateDnsHostname_thumb_4A26F876.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-10-metablogapi/8741.duplicateDnsHostname_5F00_thumb_5F00_4A26F876.png" width="468" height="168" /></a></p>  <p>To work around this situation, you can deploy your “Cloud Numerics” cluster with a different Windows Azure service name. </p>  <p>For example, if your first attempt specified the service name “<a href="https://social.technet.microsoft.com/wiki/contents/articles/1117.aspx">contoso</a>,” you could either choose another name or add a few characters to the end of this name to differentiate it from the service that is already deployed and in use. For example, you could try again using “contosopharmaceuticals.” Your fully qualified domain name for your Windows Azure service would then be contosopharmaceuticals.cloudapp.net.</p>]]></content:encoded>
    </item>
    <item>
      <title>“Cloud Numerics” Example: Statistics Operations to Azure Data</title>
      <link>https://docs.microsoft.com/archive/blogs/cloudnumerics/cloud-numerics-example-statistics-operations-to-azure-data</link>
      <pubDate>Mon, 30 Jan 2012 13:04:46 GMT</pubDate>
      <dc:creator><![CDATA[Roope Astala - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cloudnumerics/2012/01/30/cloud-numerics-example-statistics-operations-to-azure-data/</guid>
      <description><![CDATA[This post demonstrates how to use Microsoft.Numerics C# API to perform statistical operations on...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClass6361B80DCAFD43599F8A89A8BDE11F2F">   <p class="ExternalClassAC9853DD23F642EB8DC247D9E4313D45">This post demonstrates how to use Microsoft.Numerics C# API to perform statistical operations on data in Windows Azure blob storage. We go through the steps of loading data using IParallelReader interface, performing distributed statistics operations, and saving results to blob storage. As we sequence through the steps, we highlight the code samples from the application. </p>    <table border="0" cellspacing="0" cellpadding="0" width="663"><tbody>       <tr>         <td valign="bottom" width="26">&#160;</td>          <td valign="bottom" width="635"><font color="#000000"><em><strong>Note!</strong></em></font></td>       </tr>        <tr>         <td valign="top" width="26">&#160;</td>          <td valign="top" width="635">You will need to download and install the “Cloud Numerics” lab in order to run this example. To begin that process, click <a href="https://connect.microsoft.com/site1267/SelfNomination.aspx?ProgramID=7456&amp;pageType=1">here</a>.</td>       </tr>     </tbody></table> </div>  <h1>Before You Run the Sample Application</h1>  <div class="ExternalClass6361B80DCAFD43599F8A89A8BDE11F2F">   <p>Before you run the sample “Cloud Numerics” statistics application, complete the instructions in the “<a href="https://social.technet.microsoft.com/wiki/contents/articles/5993.microsoft-codename-cloud-numerics.aspx">Cloud Numerics” Getting Started</a> wiki post to:</p>    <ul>     <li>Create a Windows Azure account (if you do not have one already). </li>      <li>Install “Cloud Numerics” on your local computer where you build and develop applications with Visual Studio. </li>      <li>Configure and deploy a cluster in Azure (only if you have not done so already). </li>      <li>Submit the sample C# “Cloud Numerics” program to Windows Azure as a test that your cluster is running properly. </li>      <li>Download the project file and source code for the sample “Cloud Numerics” statistics application. </li>   </ul>    <p>&#160;</p>    <h1>Blob Locations and Sample Application Download</h1>    <p class="ExternalClassAC9853DD23F642EB8DC247D9E4313D45">You can download the sample application from the Microsoft Connect site (<a href="https://connect.microsoft.com/">connect.microsoft.com</a>). If you have not already registered for the lab, you can do that <a href="https://connect.microsoft.com/site1267/SelfNomination.aspx?ProgramID=7456&amp;pageType=1">here</a>. Registering for the lab provides you access to the “Cloud Numerics” lab materials (installation package, reference documentation, and sample applications).</p>    <table border="0" cellspacing="0" cellpadding="0" width="663"><tbody>       <tr>         <td valign="bottom" width="26">&#160;</td>          <td valign="bottom" width="635"><font color="#000000"><em><strong>Note!</strong></em></font></td>       </tr>        <tr>         <td valign="top" width="26">&#160;</td>          <td valign="top" width="635">If you are signed into Microsoft Connect, and you have already registered for your invitation to the “Cloud Numerics” lab, you can access the various sample applications using this <a href="https://connect.microsoft.com/site1267/Downloads/DownloadDetails.aspx?DownloadID=40598">link</a>.</td>       </tr>     </tbody></table>    <p class="ExternalClassAC9853DD23F642EB8DC247D9E4313D45">&#160;</p>    <p class="ExternalClassAC9853DD23F642EB8DC247D9E4313D45">For your convenience, we have staged sample datasets of pseudorandom numbers in Windows Azure Blob Storage. You can access the small and medium datasets at their respective links:</p>    <div class="ExternalClassAC9853DD23F642EB8DC247D9E4313D45">     <ul>       <li><a href="https://cloudnumericslab.blob.core.windows.net/smalldata">https://cloudnumericslab.blob.core.windows.net/smalldata</a> </li>        <li><a href="https://cloudnumericslab.blob.core.windows.net/mediumdata">https://cloudnumericslab.blob.core.windows.net/mediumdata</a> </li>     </ul>   </div>    <p>These datasets are intended merely as examples to get you started. Also, feel free to customize the sample application code to suit your own datasets.</p>    <h1>Choosing the Mode: Run on Local Development Machine or on Windows Azure</h1>    <h3>To run the application on your local workstation:</h3>    <ol>     <li>Set <strong>StatisticsCloudApplication</strong> as your StartUp project within Visual Studio. (From Solution Explorer in the Visual Studio IDE, right click the <strong>StatisticsCloudApplication</strong> subproject and select <strong>Set as Startup Project</strong>). Although, your application will run on your local workstation, the application will continue to use Windows Azure storage for data input and output. </li>      <li>Change Start Option paths for the project properties to reflect your local machine.        <br /><strong>a.</strong>&#160; Right click the <strong>StatisticsCloudApplication</strong> subproject, and select Properties.         <br /><strong>b.</strong>&#160; Click the <strong>Debug</strong> tab         <br /><strong>c.</strong>&#160; In the <strong>Start Options</strong> section of the <strong>Debug</strong> tab, edit the following fields to reflect the paths on your local development machine:         <br />&#160;&#160;&#160;&#160; <strong>-</strong>&#160; For the <strong>Command line arguments</strong> field, change:         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; c:\users\roastala\documents\visual studio 2010\Projects… to&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; c:\users\&lt;YourUsername&gt;\documents\visual studio 2010\Projects… <strong>&#160;&#160;&#160;&#160; -</strong>&#160; For the <strong>Working directory</strong> field, change:&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; c:\users\roastala\documents\… to         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; c:\users\&lt;YourUsername&gt;\documents\… </li>   </ol>    <ol>&#160;&#160;&#160;&#160; --Where c:\users\&lt;YourUsername&gt;\ reflects the home directory of the user on the local development machine where you installed the “Cloud Numerics” software. </ol>    <h3>To submit the application to Windows Azure (run on Windows Azure rather than locally):</h3>    <p>Set <strong>AppConfigure</strong> as the StartUp project. (From Solution Explorer in the Visual Studio IDE, right click the <strong>AppConfigure</strong> subproject and select <strong>Set as Startup Project).</strong></p>    <table border="0" cellspacing="0" cellpadding="0" width="663"><tbody>       <tr>         <td valign="bottom" width="26">&#160;</td>          <td valign="bottom" width="635"><font color="#000000"><em><strong>Note!</strong></em></font></td>       </tr>        <tr>         <td valign="top" width="26">&#160;</td>          <td valign="top" width="635">If you have already deployed your cluster or if it was pre-deployed by your site administrator, do not deploy it again. Instead, you only need to build the application and submit the main executable as a job.</td>       </tr>     </tbody></table>    <h1>Step 1: Supply Windows Azure Storage Account Information for Output</h1>    <p>To build the application you must have a Windows Azure storage account for storing the output. Replace the string values “myAccountKey” and “myAccountName” with your own account key and name.</p>    <pre class="code"><span style="color: blue">static string </span>outputAccountKey = <span style="color: #a31515">&quot;myAccountKey&quot;</span>;
<span style="color: blue">static string </span>outputAccountName = <span style="color: #a31515">&quot;myAccountName&quot;</span>;</pre>

  <p>The application creates a public blob for the output under this storage account. See Step 4 for details.</p>

  <h1>Step 2: Read in Data from Blob Storage Using IParallelReader Interface</h1>

  <p>Let us take a look at code in AzureArrayReader.cs file.</p>

  <p>The input array in this example is in Azure blob storage, where each blob contains a subset of columns of the full array. By using the Microsoft.Numerics.Distributed.IO.IParallelReader interface we can read the blobs in distributed fashion and concatenate the slabs of columns into a single large distributed array.</p>

  <p>First, we implement the ComputeAssignment method, which assigns blobs to the MPI ranks of our distributed computation. </p>

  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span>[] ComputeAssignment(<span style="color: #0000ff">int</span> nranks)<br />{<br />    Object[] blobs = <span style="color: #0000ff">new</span> Object[nranks];<br /><br />    var blobClient = <span style="color: #0000ff">new</span> CloudBlobClient(accountName);<br />    var matrixContainer = blobClient.GetContainerReference(containerName);<br />    var blobCount = matrixContainer.ListBlobs().Count();<br />    <span style="color: #0000ff">int</span> maxBlobsPerRank = (<span style="color: #0000ff">int</span>)Math.Ceiling((<span style="color: #0000ff">double</span>)blobCount / (<span style="color: #0000ff">double</span>)nranks);<br />    <span style="color: #0000ff">int</span> currentBlob = 0;<br />    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; nranks; i++)<br />    {<br />        <span style="color: #0000ff">int</span> step = Math.Max(0, Math.Min(maxBlobsPerRank, blobCount - currentBlob));<br />        blobs[i] = <span style="color: #0000ff">new</span> <span style="color: #0000ff">int</span>[] { currentBlob, step };<br />        currentBlob = currentBlob + step;<br />    }<br />    <span style="color: #0000ff">return</span> (<span style="color: #0000ff">object</span>[])blobs;<br />}</pre>

    <br /></div>
  <span style="color: blue"></span>

  <p>Next, we implement the property DistributedDimension, which in this case is initialized to 1 so that slabs will be concatenated along the column dimension.</p>

  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> DistributedDimension<br />{<br />    get { <span style="color: #0000ff">return</span> 1; }<br />    set { }<br />}</pre>

    <br /></div>

  <p>The ReadWorker method:</p>

  <ol>
    <li>Reads the blob metadata that describes the number of rows and columns in a given slab. </li>

    <li>Checks that the slabs have an equal number of rows so they can be concatenated columnwise. </li>

    <li>Reads the binary data from blobs. </li>

    <li>Constructs a local NumericDenseArray. </li>
  </ol>

  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> msnl.NumericDenseArray&lt;<span style="color: #0000ff">double</span>&gt; ReadWorker(Object assignment)<br />{<br />    var blobClient = <span style="color: #0000ff">new</span> CloudBlobClient(accountName);<br />    var matrixContainer = blobClient.GetContainerReference(containerName);<br />    <span style="color: #0000ff">int</span>[] blobs = (<span style="color: #0000ff">int</span>[])assignment;<br />    <span style="color: #0000ff">long</span> i, j, k;<br />    msnl.NumericDenseArray&lt;<span style="color: #0000ff">double</span>&gt; outArray;<br />    var firstBlob = matrixContainer.GetBlockBlobReference(<span style="color: #006080">&quot;slab0&quot;</span>);<br />    firstBlob.FetchAttributes();<br />    <span style="color: #0000ff">long</span> rows = Convert.ToInt64(firstBlob.Metadata[<span style="color: #006080">&quot;dimension0&quot;</span>]);<br />    <span style="color: #0000ff">long</span>[] columnsPerSlab = <span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[blobs[1]];<br />    <span style="color: #0000ff">if</span> (blobs[1] &gt; 0)<br />    {<br />        <span style="color: #008000">// Get blob metadata, validate that each piece has equal number of rows</span><br />        <span style="color: #0000ff">for</span> (i = 0; i &lt; blobs[1]; i++)<br />        {<br />            var matrixBlob = matrixContainer.GetBlockBlobReference(<span style="color: #006080">&quot;slab&quot;</span> + (blobs[0] + i).ToString());<br />            matrixBlob.FetchAttributes();<br />            <span style="color: #0000ff">if</span> (Convert.ToInt64(matrixBlob.Metadata[<span style="color: #006080">&quot;dimension0&quot;</span>]) != rows)<br />            {<br />                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> System.IO.InvalidDataException(<span style="color: #006080">&quot;Invalid slab shape&quot;</span>);<br />            }<br />            columnsPerSlab[i] = Convert.ToInt64(matrixBlob.Metadata[<span style="color: #006080">&quot;dimension1&quot;</span>]);<br />        }<br /><br />        <span style="color: #008000">// Construct output array</span><br />        outArray = msnl.NumericDenseArrayFactory.Create&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, columnsPerSlab.Sum() });<br /><br />        <span style="color: #008000">// Read data</span><br />        <span style="color: #0000ff">long</span> columnCounter = 0;<br />        <span style="color: #0000ff">for</span> (i = 0; i &lt; blobs[1]; i++)<br />        {<br />            var matrixBlob = matrixContainer.GetBlobReference(<span style="color: #006080">&quot;slab&quot;</span> + (blobs[0] + i).ToString());<br />            var blobData = matrixBlob.DownloadByteArray();<br />            <span style="color: #0000ff">for</span> (j = 0; j &lt; columnsPerSlab[i]; j++)<br />            {<br />                <span style="color: #0000ff">for</span> (k = 0; k &lt; rows; k++)<br />                {<br />                    outArray[k, columnCounter] = BitConverter.ToDouble(blobData, (<span style="color: #0000ff">int</span>)(j * rows + k) * 8);<br />                }<br />                columnCounter = columnCounter + 1;<br />            }<br />        }<br />    }<br />    <span style="color: #0000ff">else</span><br />    {<br />        <span style="color: #008000">// If a rank was assigned zero blobs, return empty array</span><br />        outArray = msnl.NumericDenseArrayFactory.Create&lt;<span style="color: #0000ff">double</span>&gt;(<span style="color: #0000ff">new</span> <span style="color: #0000ff">long</span>[] { rows, 0 });<br />    }<br />    <span style="color: #0000ff">return</span> outArray;<br />}</pre>

    <br /></div>

  <p>When an instance of reader is invoked by the Microsoft.Numerics.Distributed.IO.Loader.LoadData method, the ReadWorker instances are executed in parallel on each rank, and the LoadData method automatically takes care of concatenating the local pieces produced by the ReadWorkers.</p>

  <h1>Step 3: Compute Statistics Operations on Distributed Data</h1>

  <p>The source code in the Statistics.cs file implements the statistics operations performed on distributed data. </p>

  <p>The sample data is stored at:</p>

  <pre class="code"><span style="color: blue">static string </span>inputAccountName = <span style="color: #a31515">@&quot;https://cloudnumericslab.blob.core.windows.net&quot;</span>;</pre>

  <p>This is a storage account for our data. It contains the samples of random numbers in publicly readable containers named “smalldata” and “mediumdata.”</p>

  <p>In the beginning of the main entry point of the application, we initialize the Microsoft.Numerics distributed runtime. This allows us to execute distributed operations by calling Microsoft.Numerics library methods.</p>

  <pre class="code">Microsoft.Numerics.<span style="color: #2b91af">NumericsRuntime</span>.Initialize();</pre>

  <p>Next, we instantiate the array reader described earlier, and read data from blob storage.</p>

  <pre class="code"><span style="color: blue">var </span>dataReader = <span style="color: blue">new </span>AzureArrayReader.<span style="color: #2b91af">AzureArrayReader</span>(inputAccountName, arraySize);

<span style="color: blue">var </span>x = msnd.IO.<span style="color: #2b91af">Loader</span>.LoadData&lt;<span style="color: blue">double</span>&gt;(dataReader);</pre>

  <p>The output x is a columnwise distributed array loaded with the sample data. We then compute the statistics of the data: min, max, mean, median and percentiles, and write the results to an output string.</p>

  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Compute summary statistics: max, min, mean, median</span><br />output.AppendLine(<span style="color: #006080">&quot;Summary statistics\n&quot;</span>);<br />var xMin = ArrayMath.Min(x);<br />output.AppendLine(<span style="color: #006080">&quot;Minimum, &quot;</span> + xMin);<br />var xMax = ArrayMath.Max(x);<br />output.AppendLine(<span style="color: #006080">&quot;Maximum, &quot;</span> + xMax);<br />var xMean = Descriptive.Mean(x);<br />output.AppendLine(<span style="color: #006080">&quot;Mean, &quot;</span> + xMean);<br />var xMedian = Descriptive.Median(x);<br />output.AppendLine(<span style="color: #006080">&quot;Median, &quot;</span> + xMedian);<br /><br /><span style="color: #008000">// Compute 10% quantiles</span><br />var tenPercentQuantiles = Descriptive.QuantilesExclusive(x, 10, 0).ToLocalArray();</pre>

    <br /></div>

  <p>As x is a distributed array, the overloaded variant of the method (QuantilesExclusive) that distributes processing over nodes of the Azure cluster is used. Note that the result of the quantiles operation is a distributed array. We copy it to a local array in order to write the result to an output string.</p>

  <h1>Step 4: Write Results to Blob Storage as a .csv File</h1>

  <p>The application, by default, writes the result to the file system of the virtual cluster. This storage is not permanent; the file will be removed when you delete the cluster. The application creates a public blob on the named Azure account you supplied in the beginning of the application.</p>

  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &quot;Courier New&quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Write output to blob storage</span><br />var storageAccountCredential = <span style="color: #0000ff">new</span> StorageCredentialsAccountAndKey(outputAccountName, outputAccountKey);<br />var storageAccount = <span style="color: #0000ff">new</span> CloudStorageAccount(storageAccountCredential, <span style="color: #0000ff">true</span>);<br />var blobClient = storageAccount.CreateCloudBlobClient();<br />var resultContainer = blobClient.GetContainerReference(outputContainerName);<br />resultContainer.CreateIfNotExist();<br />var resultBlob = resultContainer.GetBlobReference(outputBlobName);<br /><br /><span style="color: #008000">// Make result blob publicly readable,</span><br /><span style="color: #008000">// so it can be accessed using URI</span><br /><span style="color: #008000">// https://&lt;accountName&gt;.blob.core.windows.net/statisticsresult/statisticsresult</span><br />var resultPermissions = <span style="color: #0000ff">new</span> BlobContainerPermissions();<br />resultPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;<br />resultContainer.SetPermissions(resultPermissions);<br /><br />resultBlob.UploadText(output.ToString());</pre>

    <br /></div>

  <p>You can then view and download the results by using a web browser to open the blob. For example, the syntax for the URI would be:</p>

  <p>https://&lt;accountName&gt;.blob.core.windows.net/statisticsresult/statisticsresult</p>

  <p>--Where &lt;accountName&gt; is the name of the cluster account you deployed to Windows Azure.</p>
</div>]]></content:encoded>
    </item>
  </channel>
</rss>