Code Monkey home page Code Monkey logo

Comments (5)

kMutagene avatar kMutagene commented on June 25, 2024 1

@7sharp9 if you just want to visualize your data and do not care about the fit function that creates the surface, you can just use Chart.Surface from Plotly.NET as @bvenn suggested. However i think if you are interested in the coefficients that fit the surface, we'd need an equivalent of numpy.polyfit which to my knowledge is not implemented in FSharp.Stats.

As i do not know how your data looks like, here is a example that contains some boilerplate to generate some 2D data that also visualizes the points from the input across the surface:

//---------------------- Generate linearly spaced vector ----------------------
let linspace (min, max, n) =
    if n <= 2 then
        failwithf "n needs to be larger then 2"

    let bw = float (max - min) / (float n - 1.)
    Array.init n (fun i -> min + (bw * float i))

//---------------------- Create example data ----------------------
let size = 100

let x = linspace (-2. * Math.PI, 2. * Math.PI, size) // 100 evenly spaced samples between -2π and 2π
let y = linspace (-2. * Math.PI, 2. * Math.PI, size) // 100 evenly spaced samples between -2π and 2π

let f x y = -(5. * x / (x ** 2. + y ** 2. + 1.)) // function to generate z based on x and y: f(x,y) = -(5 * x / (x^2 + y^2 + 1))

let xyz = Array.init size (fun i -> Array.init size (fun j -> x.[j], y.[i], f x.[j] y.[i])) |> Array.concat // generate x,y,z triplets for point plot
let zArray = Array.init size (fun i -> Array.init size (fun j -> f x.[j] y.[i])) // generate z values for surface plot

[
    Chart.Point3D(xyz, Marker = Marker.init(Size = 1, Color = Color.fromString "blue"))
    Chart.Surface(zData = z, X = x, Y = y)
]
|> Chart.combine

image

from fsharp.stats.

bvenn avatar bvenn commented on June 25, 2024

Do you just want to have some kind of regression or just a smoothed interpolation of each point?
Currently FSharp.Stats is capable of smoothing two-dimensional data only, but if you just need and interpolation and the visualization to be smooth, you can just use a Plotly surface plot. The smooting is performed automatically and may even be adjustable (https://plotly.net/reference/plotly-net-chart3d-chart.html#Surface).

An example can be seen here or here.

from fsharp.stats.

7sharp9 avatar 7sharp9 commented on June 25, 2024

Hi, thanks for the reply, to be honest just looking for any particular solutions, I have a certain amount of data which I want tto plot a surface for, the surface points should not stray away from the data set I have to interpolation like the thin plate spline seem to match my data the best but Ive also managed to replicate in 2d each dimension using tanh or arctan curves. So a F# solution of any sort would suffice for me. F# is th eeasy bits its just figuring out how from samples really.

from fsharp.stats.

7sharp9 avatar 7sharp9 commented on June 25, 2024

If regression is a really close match to my input data I could use that too, but only if the surface is only ever higher than my plotted points, and not by very much.

from fsharp.stats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.