# guilhermesob/fsharp-gradientdescent-machinelearning-basics architecture

> Architecture diagram of the GitHub repository guilhermesob/fsharp-gradientdescent-machinelearning-basics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics
- Repository: https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics

## Overview

##### Project type and purpose
- This is a command-line, scientific-computing project in F# that demonstrates a basic machine-learning optimization algorithm (Gradient Descent) for linear regression cost-function minimization.
- It’s neither a full-stack web app nor a microservice, but a focused library+CLI tool with unit tests.

##### File structure
- Top level:
- `.github/workflows/fs.yml` – CI pipeline for build & test
- `Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/` – main project directory
- `LICENSE`, `README.md`
- Inside the project directory:
- `*.fsproj` – .NET Core/F# project file
- `src/` – modules implementing:
– CostFunction.fs
– GradientDescent.fs
– LinearRegression.fs
– Optimization.fs
– Main.fs (entry point)
- `tests/` – unit tests for each module

##### README for additional insights
- Explains the mathematics of the cost function and gradient descent
- Shows example usage: arrays `x`, `y` → `gradientDescent` → output `theta`
- Outlines development & test commands (`dotnet run`, `dotnet test`)

##### Elements
- Data flow from Program → GradientDescent
- Calls from GradientDescent → CostFunction & Optimization
- Results flowing back to Program
- Tests invoking each module
- Core algorithm modules (e.g., blue)
- Entry point & CLI (e.g., green)
- Tests (e.g., orange)
- External tech (e.g., gray)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    CLI["CLI Entry Point (Program/Main.fs)"]:::entrypoint
    click CLI "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/Program.fs"

    %% Algorithm Modules
    subgraph "Algorithm Modules"
        direction TB
        Cost["CostFunction"]:::core
        click Cost "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/src/CostFunction.fs"
        Grad["GradientDescent"]:::core
        click Grad "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/src/GradientDescent.fs"
        Opt["Optimization"]:::core
        click Opt "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/src/Optimization.fs"
        LinReg["LinearRegression"]:::core
        click LinReg "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/src/LinearRegression.fs"
    end

    %% Unit Tests
    subgraph "Unit Test Suite"
        direction TB
        CFTest["CostFunctionTests"]:::tests
        click CFTest "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/tests/CostFunctionTests.fs"
        GDTest["GradientDescentTests"]:::tests
        click GDTest "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/tests/GradientDescentTests.fs"
        LRTest["LinearRegressionTests"]:::tests
        click LRTest "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/tests/LinearRegressionTests.fs"
        OptTest["OptimizationTests"]:::tests
        click OptTest "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/tests/OptimizationTests.fs"
    end

    %% External
    CI["CI Pipeline (.github/workflows/fs.yml)"]:::external
    click CI "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/.github/workflows/fs.yml"
    Runtime[".NET Core Runtime & F# Compiler"]:::external
    FSProj["Project File (.fsproj)"]:::external
    click FSProj "https://github.com/guilhermesob/fsharp-gradientdescent-machinelearning-basics/blob/main/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics/Guilhermesob-FSharp-GradientDescent-MachineLearning-Basics.fsproj"

    %% Flows
    CLI -->|"start with x,y arrays"| Grad
    Grad -->|"compute errors"| Cost
    Grad -->|"θ update loop"| Opt
    CLI -->|"prepare/format data"| LinReg
    LinReg -->|"invoke gradient descent"| Grad
    Grad -->|"return θ values"| CLI

    CFTest -->|tests CostFunction| Cost
    GDTest -->|tests GradientDescent| Grad
    LRTest -->|tests LinearRegression| LinReg
    OptTest -->|tests Optimization| Opt

    CI -->|triggers build & tests| CLI
    CI -->|runs| CFTest
    CI -->|runs| GDTest
    CI -->|runs| LRTest
    CI -->|runs| OptTest

    Runtime -->|executes| CLI
    Runtime -->|hosts modules| Cost
    Runtime -->|hosts modules| Grad
    Runtime -->|hosts modules| Opt
    Runtime -->|hosts modules| LinReg

    %% Styles
    classDef entrypoint fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef core fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef tests fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:1px
```
