Skip to content

Instantly share code, notes, and snippets.

def gen_tprf(predictions, positive_count=None, shuffle=True, sort=True):
predictions = predictions if not shuffle else \
fx.shuffle(predictions)
predictions = predictions if not sort else \
sorted(predictions, key=lambda p: -p.p)
N = positive_count if positive_count is not None else \
sum(1 for x in predictions if x.y == 1)
tp = 0
sealed abstract class FreeAlt[F[_], A] extends Product with Serializable { self =>
import FreeAlt._
def map[B](f: A => B): FA[F, B] = self match {
case Pure(a) => FreeAlt.pure(f(a))
case Ap(pivot, fn) => FreeAlt.ap(pivot)(fn.map(f compose _))
case Alt(pivot, fn) => FreeAlt.alt(pivot)(fn.map(f compose _))
}
final def ap[B](b: FA[F, A => B]): FA[F, B] =
package catz.base
import BasePackage._
import catz.base.Liskov.id
/**
* Liskov substitutability: A better `<:<`.
*
* `Liskov[A, B]` witnesses that `A` can be used in any negative context
* that expects a `B`. (e.g. if you could pass an `A` into any function
module Main
import Interfaces.Verified as V
import Control.Isomorphism
%hide Category
%hide Control.Category.Category
%default total
interface Category (cat : t -> t -> Type) where
def train_adadelta(func, fprime, x0, x_min, x_max,
step_rate=1, decay=0.9, momentum=0, offset=1e-4,
iterations=1000, tolerance=1e-1):
x_min = x_min if x_min is not None else (np.ones_like(x0) * (-np.inf))
x_max = x_max if x_max is not None else (np.ones_like(x0) * np.inf)
clamp = lambda x: np.where(x < x_min, x_min,
np.where(x > x_max, x_max, x))
bounce = lambda x, dx: np.where(x + dx < x_min, x_min - x,
np.where(x + dx > x_max, x_max - x, dx))
data Equal: (a : k) -> (b : k) -> Type where
MkEqual : ({f : k -> Type} -> f a -> f b) -> Equal a b
subst : {f : k -> Type} -> Equal a b -> f a -> f b
subst (MkEqual ab) fa = ab fa
refl' : Equal a a
refl' = MkEqual id
sym' : Equal a b -> Equal b a
package catz.base
import catz.base.BasePackage._
import catz.base.Leibniz.refl
/**
* The data type `Leibniz` is the encoding of Leibnitz’ law which states that
* if `a` and `b` are identical then they must have identical properties.
* Leibnitz’ original definition reads as follows:
* a ≡ b = ∀ f .f a ⇔ f b
@sir-wabbit
sir-wabbit / Leibniz.scala
Last active March 15, 2017 01:40
Proving stuff in Scala
sealed abstract class Eq[+H, A <: H, B <: H] private[Eq] () { ab =>
def rewrite[F[_ <: H]](fa: F[A]): F[B]
final def coerce(a: A): B =
rewrite[({type f[α] = α})#f](a)
final def andThen[H2 >: H, C <: H2](bc: Eq[H2, B, C]): Eq[H2, A, C] =
Eq.trans[H2, A, B, C](bc, ab)
final def compose[H2 >: H, Z <: H2](za: Eq[H2, Z, A]): Eq[H2, Z, B] =
sealed trait Data { self =>
type Type >: self.type <: Data
type Value
implicitly[Type <:< Type#Type]
implicitly[self.type <:< Type]
}
sealed trait DataF[T <: DataF[T]] extends Data { self : T =>
// type Type >: self.type <: DataF[T]
type Type = T
Type Functor Apply Applicative Bind Monad MonoidK MonadError Cobind Comonad
Id[A]
Option[A]
Const[K, A] ✔ (K:Monoid) ? ?
Either[E, A]
List[A]
NonEmptyList[A]