
Good Morning Racket!

or more like good lunch around here

So was trying to find any existing functions like residual sum of squares and the likes (along the lines of metrics in scikit-learn http://scikit-learn.org/stable/modules/classes.html#sklearn-metrics-metrics ). Does anyone know of any package that is ok maintained with this type of stuff? The closest I found was https://github.com/n3mo/data-science

It’s easy enough to program some but they already exist why reinvent the wheel



Is there a modern package for the Science Collection ?

yeah I checked out the general stats one

let me see the other link

hum seems like standard math has a lot of equivalent parts of the Science Collection

think I’ll just put together a small metrics library

by the way

is (Sequenceof A) the more general approach to deal with list like things?

another thing there isn’t anything like a dataframe in Racket is there? I mean I am mostly okay with just arrays and lists of lists


and Alex Harsanyi is working on his own version here: https://github.com/alex-hhh/ActivityLog2/tree/master/rkt/data-frame

currently part of ActivityLog2

cool

Any idea how I can get the test to work? > (array #[#[2 2] #[2 2]])
- : (Array Positive-Byte)
(array #[#[2 2] #[2 2]])
> (random-array #(2 2) 2 3)
- : (Array Integer)
(array #[#[2 2] #[2 2]])

--------------------
random-array tests
. ERROR
check-equal?: contract violation
any-wrap/c: Unable to protect opaque value passed as `Any`
value: (array #[#[2 2] #[2 2]])
in: the 1st argument of
(->* (Any Any) (any/c) any/c)
contract from: (interface for check-equal?)
blaming: <pkgs>/rackunit-typed/rackunit/main.rkt
(assuming the contract is correct)
at: <pkgs>/rackunit-typed/rackunit/main.rkt:22.2
--------------------

even more wierd is that > (equal? (random-array #(2 2) 2 3) (array #[#[2 2] #[2 2]]))
- : Boolean
#t

don’t quite understand why equal? works fine and check-equal? doesn’t..!

@andika.riyan has joined the channel

So optimization coach says the following about norm-l2
: This expression has a Complex type, despite all its arguments being reals. If you do not want or expect complex numbers as results, you may want to restrict the type of the arguments or use float-specific operations (e.g. flsqrt), which may have a beneficial impact on performance.
. I get a green highlighting once I modify it to norm-l2-opt, is this the best way to perform this optimization (with the cast)?

thanks for any feedback :slightly_smiling_face:

hum guess real->double-flonum
is better then cast
, yes?

yeah sorry for all the questions, it’s just coming from a purely dynamically typed language like Python, guess I didn’t expect this to be so hard sometimes

I understand the benefits, but doesn’t make it easier

do you need to use flsqrt
here?

or, can you change Real
to Flonum
in the function type?

hum I’ll give it a try

Flonum instead of Float yeah?

I don’t remember the difference

oh, it looks like they’re the same but flonum
is from Scheme

hum from what I understood

to get the benefit of the optimization I have to use the fl… functions

can’t seem to find a sum one though

meh this seems a bit to much for me now will just stick to non-optimized version which seems to at least work

strange that they don’t have sum in flonum though

fl+

Don’t think it does the same

I tried using a fold but the polymorphism is just a headache to understand

#lang typed/racket
(require math/base
typed/racket/flonum)


oh, I see #lang typed/racket
(require racket/flonum)
(: flsum (-> (Listof Flonum) Flonum))
(define (flsum f*)
(for/fold ([acc : Flonum 1.0])
([f (in-list f*)])
(fl+ acc f)))

hum ok! looks nice

but

1.0 ?

here’s one way to do the fold #lang typed/racket
(require racket/flonum)
(foldl fl+ 1.0 (map exact->inexact '(1 2 3)))

guess I can just use 0.0

1.0, to put me on the “right” side of the numeric tower http://docs.racket-lang.org/ts-reference/type-ref.html?q=Numeric%20Types#%28part._.Numeric_.Types%29

ahhh!

hum but do you always have to provide a initial value

I remember using reduce (which is a fold no?) in python don’t remember having to give a first value

it would just use the first and go from there

but it’s not unbearable :stuck_out_tongue:, just a bit more verbose I guess

so is f*
a notation to describe a flonum list ?

I mean convention?

what did reduce do for an empty list?

I just like *
for lists

good question! let me check

think it returned a null

or None
to be more precise

but let me check

It actually gives an error :laughing:

>>> reduce(lambda x, y: x + y, [1])
1
>>> reduce(lambda x, y: x + y, [1, 2])
3
>>> reduce(lambda x, y: x + y, [1, 1])
2
>>> reduce(lambda x, y: x + y, [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: reduce() of empty sequence with no initial value

plus I had to write a lambda (I can import the + operator from somewhere, but to be honest it was quicker to just do the lambda)

let me try with the operator

same thing >>> reduce(operator.add, [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: reduce() of empty sequence with no initial value
>>> reduce(operator.add, [1])
1

what was even funnier is I was a bit confused I was getting an error to begin with, but then I realised I was already in Racket mode, wrote (reduce ...)

funny I have only been programming seriously for a few days and I already start feeling comfortable with that syntax

Seriously, shouldn’t these function just be in the base flonum library :stuck_out_tongue:?

flsum
is in math/flonum
. Pull requests for new things would be welcome

ah what a relief hehe

but there isn’t a flsqr so maybe I can work in that? Should be straightforward no..?

fl2sqr

..?

why no flsqr

flsqr/error

“Compute the same values as (fl+ x y), (fl- x y), (fl* x y), (fl/ x y), (fl* x x), (flsqrt x), (flexp x) and (flexpm1 x), but return the normally rounded-off low-order bits as the second value. The result is an unboxed double-double.” https://docs.racket-lang.org/math/flonum.html?q=flsqr#%28def._%28%28lib._math%2Fflonum..rkt%29._flsqrt%2Ferror%29%29

Why flsqr/error exists and not flsqr..? Is it a problem? I mean if flexpt exists why not flsqr..?

I dunno. I guess the original author figured (fl* x x)
was fine

I don’t think there’s a deep reason

hum.. little bit strange considering there is a regular sqr..! To submit a issue on racket/flonum is that in the main repository?

yes, but I think a better place is the racket/math
repo

ok :wink:

oh, for your question about check-equal?
, here’s a small program with the same issue:

#lang typed/racket/base
(require/typed racket/base
(void (-> Any Void)))
(struct foo ())
(void (foo))

Typed Racket works hard to protect types, so you can trust they predict how the program’s actually going to run

and part of that is protecting typed values that flow into untyped code

usually the type is guide for how to protect things, but when the type is Any
Typed Racket just tries its best to add protection

but it can’t add protection if the value is an opaque struct (and TR doesn’t have an inspector to learn about the struct’s fields and their types)

so basically, check-equal?
errors because its a Racket library using Any
types … this really should be fixed somehow

so let me see if I understood it’s the array struct that is opaque..?

yes

and this program doesn’t error: #lang typed/racket/base
(require/typed racket/base
(void (-> Any Void)))
(struct foo () #:transparent)
(void (foo))

ah yes, I remember reading about the #:transparent
keyword in one of the guides

hum ok, so the only way for me to get the test working is to cast it into the type I actually expect from the function I am writing (in this case (Array Integer)
) right? I mean it’s not perfect but..!

or annotate it..?

no annotate won’t work will it

(check equal? (array1) (array2))
might wor

ah ok! way simpler hehe

by the way think I actually manage to optimize the norm-… functions with the newfound knowledge, hehe. Optimization Coach gives me green lights on all functions

there is probably a nicer way of doing the last one

cool (if it was me, I’d replace all the sum (map ....)
with folds, but yeah this looks good)

hum yeah I was thinking about that, but still didn’t get my head around folds totally

oh and by “fold” I really mean for/fold
.

let me see if I can do it :slightly_smiling_face:

ah maybe tomorrow hehe… my brain went for a walk I think

I don’t quite understand why my tests are giving a problem in some other file..! They are obviously problems inmy file… I’ve wrapped my test-suite with a (define tests …) and I am using (run-tests tests). Any ideas..?

I’ve named the individual tests but still wondering why it does that..?

I’d need to see the files to help, but my favorite way to do unit tests is with a test submodule: #lang racket/base
;; ... code here
(module+ test
(require rackunit)
(check-equal? 2 2)
)

and running raco test file.rkt
does the tests, and otherwise they’re out of the way

hum ok!

anyways thanks for all the help @ben :slightly_smiling_face:

I’ll try and write down the name of everyone that helped for my acknowledgements :slightly_smiling_face:

here at the racket.slack

lol it’s all good we’re all trying to help racket succeed

I really like the language

after looking at the dozen so languages

it was the first I felt confident it would work for what I wanted

awesome thats great to hear

Haskell, Scala, D, Elixir, Oz (:laughing: ), Julia, Hy (Python) and a bunch of others

I hope we can fix the awkward/difficult parts

ah Clojure too!

That Racket had good base support for plotting, GUI and math (especially arrays/matrix) as well as just plain graphics was really enticing

couldn’t find a combination of those that worked nicely in most languages beyond Python

clojure seems like it was okay a bunch of years back but the basic libraries are way to old

plus JVM ugh.

only Julia came close, but it’s way to Beta for me

I mean they’ve been saying they’re going to release a stable version soon for years now

plus most libraries are in constant flux

what made the clojure libraries feel old? (so racket can avoid getting old, too)


Well I heard a whole talk about how it got old, seems like they’ll come around eventually but for now didn’t seem like a great ecosystem to switch too

Incanter was the main library a couple of years ago, but it has been worked on for a while now

My second choices to racket were julia and scala

Scala seems great for big data science

But for the kind of thing I’m used to in python didn’t seem to helpful

Seemed like a steep learning curve

Plus I don’t really love that everything is based on OO in Scala, even if it has good FP support. I mean it sounds in someways more true to the OO then Python and more scalable because of that

But I don’t know, the whole Java ecosystem is a bit to strange for me (I would need to interface with a bunch of java libraries to get things done)

When your used to much of the simplicity of python as an ecosystem, it feels too much

DrRacket is great in that sense, I just started doing stuff without worrying about setting uo IDEs and for some languages having to get basic syntax highlighting working

Emacs and vim is just not something I have time to learn now

I’ve written most of my stuff in python with just gedit and geany+repl when things get a bit more messy (also gave Spyder a try)

Basically coming from Python, Racket was the first thing that just worked

Without having to worry too much

Although I haven’t used the package manager it seems straightforward

And apart from the ecosystem I liked the language

I’ve been wanting to learn a lisp language for years now

Or at least a functional programming language

Ah you can add OCaml to the list, although I only looked at it very briefly since I couldn’t get the libraries I wanted working

@maxim_jaffe Have a hunch, you’ll enjoy this: https://www.cs.umd.edu/~ntoronto/papers/toronto-2014cise-floating-point.pdf

Hehe I like the title

And nice graphs!

Thanks @soegaard2 when I’m at the computer I’ll look at it

Oh btw. The function flsum adds the numbers in an order that improves accuracy.

Ah nice!

It’s working well for me in those little functions I wrote

@maxim_jaffe btw - Neil wrote plot, so don’t be surprised the article has nice graphs :slightly_smiling_face:

“Test for nearness instead of equality”. By the way for testing floating-point finction with check-=
what is a reasonable epsilon

depends

Often you can try something small. Other times you needs to be more cautious.

Something like the error in the range of what you get when you do(* 3 1.0/3.0)
(if I remember right that gives a really small error right?)

Or is that to rigid?

Depends! But read the article. Neil shows how to debug floating point calculations.

Hum ok!

Will do

:slightly_smiling_face:

By the way a channel just for typed racket could be useful no? Especially for questions on getting correct typing definitions and such

Who’s interested?

You should see the julia slack there is so many channels hehe

Practically one for each core/popular library

there are many fewer of us, so mostly people just use this channel

Yeah understandable

But at the same time might help keep annoying people like me contained :joy:

I like a little life here. It only makes sense to make new channels when there are too much activity (and it becomes confusing to follow a discussion).

Plus at julia usually the core developers/maintainers/fans of a library kept a close eye in the related channel

Hehe sure

I know what you mean

Your probably right, but still hehe


And about 100–200 in the most popular library channels

On a completely different note

Does anyone know users / developers from Brazil

Or Portugal for the matter

I used to run a small computer school

Back there and think the kids would have really liked racket / 2htdp

When I go back might give it a try

As a social project

Think the ability to make little games or videos would be popular

(I think there are some people from Brazil on the mailing list)

Cool!

Wasn’t there a spanish mailing list at some point?

Probably not where I lived though hehe

State of Piauí

Almost in the middle of nowhere

Computer literacy is really low there

Where I lived

More likely for kids to have access to smartphones and tablets then computers

By the way is there any project on getting a racket working on android and a REPL to play around with

I heard in the racket manifesto talk of matthias that there was work on the ARM processor



Hehe just found the same github

But that’s for deploying apps right?

I’m guessing this is a bug in 7.0?
raco setup: error: during making for <pkgs>/oedipuslex
raco setup: Users/ryan/Work/git/zenspider/schemers/oedipuslex/test.rkt:23:14: read-syntax: end-of-file following `\|` in symbol
raco setup: compiling: <pkgs>/oedipuslex/test.rkt
namely, that the path reported is missing the leading /
(cc @mflatt)
Possibly also that this used to work in 6.x… but I don’t know if things have been made stricter and now it is a legit failure or if it should have worked in 7. That’s separate at this point.

(these were produced via migrating packages inside of drracket, if that matters)

Looks like the package manager is already reporting an error on metapict
… how was it compiling before?

“oedipuslex” :+1:

some top-tier naming right there

:stuck_out_tongue: