This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn auc [lines] | |
| (let [[a _ n fp' p tp'] (reduce iter [0 Double/NEGATIVE_INFINITY 0 0 0 0] lines)] | |
| (/ (+ a (trap-area n fp' n tp')) | |
| (* p n)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn iter | |
| "Area Under Curve [AUC] reduce function. | |
| The element is a vector of three elements: the ID of the model, | |
| whether the classifier example is positive (pos), | |
| and the probabilistic value (f). | |
| The accumulator tracks six values, aggregated area, the last f value (f'), | |
| negative examples (fp and fp'), and positive examples (tp and tp')." | |
| [[area f' fp fp' tp tp'] [_ pos f]] | |
| (if (= f' f) | |
| [area |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn trap-area | |
| "Trapezoid area." | |
| [x1 x2 y1 y2] | |
| (* (Math/abs (- x1 x2)) | |
| (/ (+ y1 y2) 2))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| movie = Store.insert_movie(movie_map) | |
| movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all | |
| assert Enum.find(movie_list, &(&1 == movie_map["title"])) | |
| assert movie == Store.insert_movie(movie_map) | |
| assert Enum.filter(movie_list, &(&1 == movie_map["title"])) == [Enum.find(movie_list, &(&1 == movie_map["title"]))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| movie = Store.insert_movie(movie_map) | |
| movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all | |
| assert Enum.find(movie_list, &(&1 == movie_map["title"])) | |
| ^movie = Store.insert_movie(movie_map) | |
| assert Enum.filter(movie_list, &(&1 == movie_map["title"])) == [Enum.find(movie_list, &(&1 == movie_map["title"]))] | |
| Eiga.Repo.delete(movie) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| warning: variable movie is unused | |
| test/eiga/store_test.exs:22 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test "inserting movies is idempotent" do | |
| movie_map = %{"title" => "The Goonies", | |
| "short_title" => "goonies", | |
| "year" => 1985, | |
| "country" => "U.S."} | |
| movie = Store.insert_movie(movie_map) | |
| movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all | |
| assert Enum.find(movie_list, &(&1 == movie_map["title"])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.LinkedList; | |
| import java.util.List; | |
| import java.util.function.Predicate; | |
| import java.util.stream.Collectors; | |
| public final class Throttler { | |
| private final List<Throttle> throttles = new LinkedList<>(); | |
| public void addThrottle(Throttle throttle) { throttles.add(throttle); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.Optional; | |
| List<Double> doubles = Arrays.asList(3.0, 3.0, 3.0); | |
| Optional<Double> pow = doubles.stream().reduce(Math::pow); | |
| List<String> words = Arrays.asList("/a/", "b", "c"); | |
| Optional<String> result = words.stream().reduce(""::replaceFirst); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.Collections; | |
| import java.util.List; | |
| import java.util.Optional; | |
| List<Long> numbers = Collections.emptyList(); | |
| Optional<Long> result = numbers.stream().reduce(Math::max); | |
| // result.orElse(-1L) == -1L; | |
| numbers = Arrays.asList(52L, 127L, 1337L); |