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
# bisection(lambda x: x**2 - 2.0, 0, 100, 1e-15) | |
def bisection(f, a, b, err): | |
if err < 1e-15 or abs(b - a) / 2 < err: | |
return None | |
if a > b: | |
a, b = b, a | |
m = (b + a) / 2.0 | |
while (b - a) / 2.0 > err and f(m) != 0.0: | |
if f(a) * f(m) < 0.0: | |
b = m |
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
bisection :: (Double -> Double) -> Double -> Double -> Double -> Maybe Double | |
bisection f a b err | |
| err < 1e-15 = Nothing | |
| abs (b - a) / 2 < err = Nothing | |
| a < b = bis a b | |
| otherwise = bis b a | |
where | |
bis a b | |
| d < err || f m == 0.0 = Just m | |
| f a * f m < 0.0 = bis a m |
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
bisection f a b e = if a < b then bis a b else bis b a | |
where err = if e < 1e-15 then 1e-15 else e | |
bis a b = let d = (b - a) / 2; m = (b + a) / 2 in | |
if d < err then | |
m | |
else if f a * f m < 0.0 then | |
bis a m | |
else | |
bis m b |
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
=== Run information === | |
Scheme:weka.classifiers.trees.J48 -C 0.25 -M 2 | |
Relation: Dataset0 - Sheet1-weka.filters.unsupervised.attribute.Remove-R1-weka.filters.supervised.attribute.NominalToBinary-weka.filters.supervised.attribute.NominalToBinary-weka.filters.supervised.attribute.NominalToBinary-weka.filters.unsupervised.attribute.NumericToNominal-Rfirst-last | |
Instances: 21 | |
Attributes: 3 |
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
# Functions to generate networks ("graphs") for spatial ecology. | |
# | |
# Stores the graph in a rather inefficient (but easy-to-use) adjacency matrix | |
# of boolean values. | |
# | |
# Key functions: | |
# - geograph returns a random geometric graph. | |
# - cgeograph returns a connected random geometric graph. | |
# - geotree returns a random geometric tree. | |
# |
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
// Compile with: | |
// $ clang++ -O3 -std=C++11 main.cc -o main | |
#include <iostream> | |
#include <random> // The header for the generators. | |
#include <ctime> // To seed the generator. | |
using namespace std; | |
int main() { |
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
// Compile with g++ -std=c++11 -O2 main.c -o main | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <random> | |
#include <ctime> | |
#include <cstdlib> | |
using namespace std; |
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
getPrimes = f [2, 3] 5 | |
f ps n max = if n >= max then | |
ps | |
else if pr n then | |
f (ps ++ [n]) (n + 2) max | |
else | |
f ps (n + 2) max | |
where pr y = foldl (&&) True (map (\x -> mod y x > 0) ps) |
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
# Print a sequence of primes. It's not written to be fast, it's just to demonstrate | |
# than an infinite sequence can be compressed in a small program and thus have low | |
# (Kolmogorov) complexity. | |
def printprimes(max) | |
primes = [] | |
for i in 2.. max do | |
primes << i if primes.inject(true) {|res, elt| | |
res and i % elt != 0 | |
} | |
end |
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
Public preprint servers such as arXiv.org have become central to the scientific | |
process in fields such as physics, mathematics, and economics. These preprint | |
servers allow researchers to make their research rapidly available to the | |
broader community prior to peer review, which facilitates discussion, review, | |
and rapid communication of scientific results. Preprints are increasingly seen | |
as an important component of open science, because the research can be discussed | |
by the scientific community as soon as it is finished, instead of being | |
virtually hidden until officially published. However, in contrast to other | |
disciplines, the field of biology has effectively no preprint culture, with the | |
exception of small pockets of primarily highly quantitative research (e.g., |