Initial commit — Coursera Big Data coursework

This commit is contained in:
2026-05-09 03:03:14 +00:00
commit c85c238e41
30 changed files with 2488 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0"/>
<bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
+79
View File
@@ -0,0 +1,79 @@
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
type Cond = char * bool
type P = Cond List * double
type Variable =
| OneD of Cond * Cond * double
| TwoD of Cond * Cond * Cond * double
| Prior of Cond * double
let getProbability(p) =
match p with
| OneD(_,_,prob) -> prob
| TwoD(_,_,_,prob) -> prob
| Prior(_,prob) -> prob
let filterCondition (c, b) v =
match v with
| OneD((pc,pb),_,_) when c = pc && b = pb -> true
| OneD(_,(pc,pb),_) when c = pc && b = pb -> true
| Prior((pc,pb),_) when c = pc && b = pb -> true
| TwoD((pc,pb),_,_,_) when c = pc && b = pb -> true
| TwoD(_,(pc,pb),_,_) when c = pc && b = pb -> true
| TwoD(_,_,(pc,pb),_) when c = pc && b = pb -> true
| _ -> false
let reciprocal v =
match v with
| Prior((pc,pb),p) -> Prior((pc,not pb),1.0-p)
| OneD((pc,pb),a,p) -> OneD((pc,not pb),a,1.0-p)
| TwoD((pc,pb),a,b,p) -> TwoD((pc,not pb),a,b,1.0-p)
let matchProb cond variables = cond |> List.fold (fun s c -> List.filter (filterCondition c) s) variables |> List.head |> getProbability
let completeReciprocalVariable variable = variable |> List.map reciprocal |> List.append variable
//let addNeg ps = ps concat ps
//let pa = [Prior(('a', true), 0.01)]
//
//let pta = [OneD(('t', true), ('a', true), 0.5);
// OneD(('t', true), ('a', false), 0.1)]
//
//let ps = [Prior(('s', true), 0.5)]
//
//let pls = [OneD(('l', true), ('s', true), 0.1);
// OneD(('l', true), ('s', false), 0.01)]
//
//let pbs = [OneD(('b', true), ('s', true), 0.6);
// OneD(('b', true), ('s', false), 0.3)]
let pm = [Prior(('m',true), 0.1)] |> completeReciprocalVariable
let pbm = [OneD(('b',true), ('m',true), 0.9); OneD(('b',true), ('m',false), 0.05)] |> completeReciprocalVariable
let psm = [OneD(('s',true), ('m',true), 0.6); OneD(('s',true), ('m',false), 0.3)] |> completeReciprocalVariable
let pbym = (pm |> matchProb [('m', true)]) * (pbm |> matchProb [('b',true);('m',true)]) , (pm |> matchProb [('m', false)]) * (pbm |> matchProb [('b',true);('m',false)])
let pbysym = (pm |> matchProb [('m', true)]) * (pbm |> matchProb [('b',true);('m',true)]) * (psm |> matchProb [('s',true);('m',true)]),
(pm |> matchProb [('m', false)]) * (pbm |> matchProb [('b',true);('m',false)]) * (psm |> matchProb [('s',true);('m',false)])
let ps = [Prior(('s',true), 0.3)] |> completeReciprocalVariable
let pr = [Prior(('r',true), 0.2)] |> completeReciprocalVariable
let pwsr = [TwoD(('w',true), ('s',true), ('r',true), 0.9); TwoD(('w',true), ('s',true), ('r',false), 0.7);
TwoD(('w',true), ('s',false), ('r',true), 0.8); TwoD(('w',true), ('s',false), ('r',false), 0.1); ] |> completeReciprocalVariable
let pwyr = (pr |> matchProb [('r', true)]) *
((pwsr |> matchProb [('r',true);('w',true);('s',true)]) * (ps |> matchProb [('s',true)]) +
(pwsr |> matchProb [('r',true);('w',true);('s',false)]) * (ps |> matchProb [('s',false)]))
[<EntryPoint>]
let main argv =
printfn "%A" pwyr
0 // return an integer exit code
+62
View File
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>09058fa2-2e33-4839-beb2-26e0f0cf261f</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>hw6</RootNamespace>
<AssemblyName>hw6</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>hw6</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Debug\hw6.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Release\hw6.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<None Include="App.config" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+26
View File
@@ -0,0 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "hw6", "hw6.fsproj", "{09058FA2-2E33-4839-BEB2-26E0F0CF261F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hw6cs", "..\hw6cs\hw6cs.csproj", "{266F814D-56C6-4BF2-8A8B-F6700E6EA920}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09058FA2-2E33-4839-BEB2-26E0F0CF261F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09058FA2-2E33-4839-BEB2-26E0F0CF261F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09058FA2-2E33-4839-BEB2-26E0F0CF261F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09058FA2-2E33-4839-BEB2-26E0F0CF261F}.Release|Any CPU.Build.0 = Release|Any CPU
{266F814D-56C6-4BF2-8A8B-F6700E6EA920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{266F814D-56C6-4BF2-8A8B-F6700E6EA920}.Debug|Any CPU.Build.0 = Debug|Any CPU
{266F814D-56C6-4BF2-8A8B-F6700E6EA920}.Release|Any CPU.ActiveCfg = Release|Any CPU
{266F814D-56C6-4BF2-8A8B-F6700E6EA920}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal