-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bbd5620
Showing
1,294 changed files
with
338,916 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import numpy | ||
import matplotlib.pyplot as plt | ||
|
||
x = np.linspace(0, np.pi, 100)) | ||
y = np.sin(x) | ||
|
||
plt.plot(x, y) | ||
|
||
plt.show() |
96 changes: 96 additions & 0 deletions
96
_downloads/4b858dab9366f77b3641c99adece5fd2/weather_observations.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
pylint exercise 1 | ||
""" | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
from sklearn import linear_model | ||
|
||
|
||
def f(x): | ||
""" | ||
Example function: | ||
f(x) = x/2 + 2 | ||
"""" | ||
return 0.5*x + 2 | ||
|
||
|
||
# Create example data | ||
x_data = np.linspace(0, 10, 100) | ||
err = 2 * np.random.random(x_data.shape[0]) | ||
y_data = f(x_data) + err | ||
|
||
# Put data into dataframe | ||
df = pd.DataFrame({'x': x_data, 'y': y_data}) | ||
|
||
# Create linear model and fit data | ||
reg = linear_model.LinearRegression(fit_intercept=True) | ||
|
||
reg.fit(df[['x'], df[['y']]) | ||
|
||
slope = reg.coef_[0][0] | ||
intercept = reg.intercept_[0] | ||
|
||
df['pred'] = reg.predict(df[['x']]) | ||
|
||
fig, ax = plt.subplots() | ||
|
||
ax.scater(df[['x']], df[['y']], alpha=0.5) | ||
ax.plot(df[['x']], df[['pred']] | ||
color='black', linestyle='--', | ||
label=f'Prediction with slope {slope:.2f} and intercept {intercept:.2f}') | ||
ax.set_ylabel('y') | ||
ax.set_xlabel('x') | ||
ax.legend() | ||
|
||
plt.show() |
38 changes: 38 additions & 0 deletions
38
_downloads/75c4ab69c0f59fbb1589b03be360a485/optionsparser.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import yaml | ||
|
||
def get_parameters(config_file, required, defaults): | ||
''' | ||
Parameters: | ||
Optionfile: FileName of the yaml file containing the options | ||
required: Dict of required argument names and their object types. | ||
defaults: Dict of default parameters mapping to their default values | ||
Returns: An object with fields named according to required and optional values. | ||
''' | ||
f = open(config_file) | ||
options = yaml.safe_load(f) | ||
# create a parameters object that allows setting attributes. | ||
parameters = type('Options', (), {})() | ||
# check required arguments | ||
for arg in required: | ||
if not arg in options: | ||
raise Exception("Could not find required Argument " + arg + " aborting...") | ||
else: | ||
if not isinstance(options[arg],required[arg]): | ||
raise Exception("Expected input of type " + str(required[arg]) + " but got " + str(type(options[arg]))) | ||
print("Setting " + arg + " to " + str(options[arg])) | ||
setattr(parameters,arg,options[arg]) | ||
# check the default values. | ||
for arg in defaults: | ||
if arg in options: | ||
if not isinstance(options[arg],type(defaults[arg])): | ||
#Wrong type for the parameter | ||
raise Exception("Expected input of type " + str(type(defaults[arg])) + " but got " + str(type(options[arg]))) | ||
print("Setting " + arg + " to " + str(options[arg])) | ||
setattr(parameters,arg,options[arg]) | ||
else: | ||
print( arg + " not found in option file. Using default: " +str(defaults[arg])) | ||
setattr(parameters,arg,defaults[arg]) | ||
return parameters | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
_downloads/a99f82e01864794e5780d2697d273d9e/code_style_example.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import numpy as np | ||
|
||
def PI_estimate(n): | ||
"""This function calculates an estimate of pi with dart thrower algorithm. | ||
""" | ||
|
||
pi_Numbers = np.random.random(size = 2*n) | ||
x = pi_Numbers[ :n ] | ||
y = pi_Numbers[ n: ] | ||
|
||
return 4*np.sum((x * x + y*y ) < 1)/n | ||
|
||
|
||
for number in range(1,8): | ||
|
||
n = 10** number | ||
|
||
print(f'Estimate for PI with {n:8d} dart throws: {PI_estimate( n )}') |
30 changes: 30 additions & 0 deletions
30
_downloads/b1df8a26f353860c500cc194df1641aa/exercise2_solution.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def dice_toss(n, m): | ||
"""Throw n dice m times and the total value together.""" | ||
dice_rolls = np.random.randint(1, 6, size=(m, n)) | ||
|
||
roll_averages = np.sum(dice_rolls, axis=-1) | ||
|
||
return roll_averages | ||
|
||
|
||
fig, ax = plt.subplots() | ||
|
||
n = int(input("Number of dices to toss:\n")) | ||
|
||
bins = np.arange(1, 6 * n + 1) | ||
|
||
m = 1000 | ||
|
||
ax.hist(dice_toss(n, m), bins=bins) | ||
|
||
ax.set_title(f"Histogram of {n} dice tosses") | ||
|
||
ax.set_xlabel("Total value") | ||
|
||
ax.set_ylabel("Number of instances") | ||
|
||
plt.show() |
47 changes: 47 additions & 0 deletions
47
_downloads/bd9ea3f34382e553b2a8efaca3708746/exercise1_solution.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
pylint exercise 1 | ||
""" | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
from sklearn import linear_model | ||
|
||
|
||
def f(x): | ||
""" | ||
Example function: | ||
f(x) = x/2 + 2 | ||
""" | ||
return 0.5*x + 2 | ||
|
||
|
||
# Create example data | ||
x_data = np.linspace(0, 10, 100) | ||
err = 2 * np.random.random(x_data.shape[0]) | ||
y_data = f(x_data) + err | ||
|
||
# Put data into dataframe | ||
df = pd.DataFrame({'x': x_data, 'y': y_data}) | ||
|
||
# Create linear model and fit data | ||
reg = linear_model.LinearRegression(fit_intercept=True) | ||
|
||
reg.fit(df[['x']], df[['y']]) | ||
|
||
slope = reg.coef_[0][0] | ||
intercept = reg.intercept_[0] | ||
|
||
df['pred'] = reg.predict(df[['x']]) | ||
|
||
fig, ax = plt.subplots() | ||
|
||
ax.scatter(df[['x']], df[['y']], alpha=0.5) | ||
ax.plot(df[['x']], df[['pred']], | ||
color='black', linestyle='--', | ||
label=f'Prediction with slope {slope:.2f} and intercept {intercept:.2f}') | ||
ax.set_ylabel('y') | ||
ax.set_xlabel('x') | ||
ax.legend() | ||
|
||
plt.show() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
def dice_toss(n,m): | ||
|
||
"""Throw n dice m times and the total value together.""" | ||
dice_rolls = np.random.randint(1,6,size=(m, n)) | ||
|
||
roll_averages = np.sum(dice_rolls,axis = -1) | ||
|
||
return roll_averages | ||
fig,ax = plt.subplots( ) | ||
|
||
n = int( input('Number of dices to toss:\n')) | ||
|
||
bins = np.arange(1, 6 * n+1) | ||
|
||
m = 1000 | ||
|
||
ax.hist(dice_toss(n,m), bins = bins) | ||
|
||
ax.set_title(f'Histogram of {n} dice tosses') | ||
|
||
ax.set_xlabel('Total value' ) | ||
|
||
ax.set_ylabel('Number of instances') | ||
|
||
plt.show() |
Oops, something went wrong.