Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
guenther
guenther
@guenther@chaos.social  ·  activity timestamp 8 hours ago

@janriemer

The implementation is not necessarily wrong, even if it may not be correct choice for your use case. Libraries that implement filters like this usually have a parameter or something where you can specify how to handle the border of the data.

What your LLM implemented is equivalent to scipy.ndimage.convolve with mode="nearest", and you wanted what numpy.convolve does with mode="valid"

https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.convolve.html

https://numpy.org/devdocs/reference/generated/numpy.convolve.html

numpy.convolve — NumPy v2.5.dev0 Manual

convolve — SciPy v1.17.0 Manual

  • Copy link
  • Flag this post
  • Block
Jan :rust: :ferris:
Jan :rust: :ferris:
@janriemer@floss.social replied  ·  activity timestamp 21 hours ago

It is because of the `map` operator on the collection we want to create the moving average (MA) on:

The resulting collection of a MA is smaller _by definition_ than the collection the MA is applied on!

`map` will create a collection of the _same_ length, so this algorithm is wrong.

I'm so tired of this shit!

If you want to read good source material for this algorithm:
https://www.statisticshowto.com/probability-and-statistics/statistics-definitions/moving-average/

(Oh, and how ironic that #LLMs get #statistics wrong... 🙃)

2/2

#LLM #Claude #Rust

  • Copy link
  • Flag this comment
  • Block
guenther
guenther
@guenther@chaos.social replied  ·  activity timestamp 8 hours ago

@janriemer

The implementation is not necessarily wrong, even if it may not be correct choice for your use case. Libraries that implement filters like this usually have a parameter or something where you can specify how to handle the border of the data.

What your LLM implemented is equivalent to scipy.ndimage.convolve with mode="nearest", and you wanted what numpy.convolve does with mode="valid"

https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.convolve.html

https://numpy.org/devdocs/reference/generated/numpy.convolve.html

numpy.convolve — NumPy v2.5.dev0 Manual

convolve — SciPy v1.17.0 Manual

  • Copy link
  • Flag this comment
  • Block
Jan :rust: :ferris:
Jan :rust: :ferris:
@janriemer@floss.social replied  ·  activity timestamp 8 hours ago

@guenther Oh wow, thank you for the explanation and the links! 😮 I didn't know that!

I have to check out your links, thanks!

I've updated the OP and linked to your toot:
https://floss.social/@janriemer/115878090852420861

  • Copy link
  • Flag this comment
  • Block
TheConstructor (he/him)
TheConstructor (he/him)
@TheConstructor@social.tchncs.de replied  ·  activity timestamp 18 hours ago

@janriemer shouldn't there be a return? There is one for empty collections…

  • Copy link
  • Flag this comment
  • Block
Bobulous :rust: :codeberg:
Bobulous :rust: :codeberg:
@bobulous@fosstodon.org replied  ·  activity timestamp 16 hours ago

@TheConstructor @janriemer The code is written in the Rust programming language, where a method or function can end with an expression which will be the returned value. So the `return` keyword is usually only used for an early return.

  • Copy link
  • Flag this comment
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-beta.24 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct