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
def expected_utility_logarithmic(simulations, a=1): | |
utilities = a * np.log(simulations) | |
return np.mean(utilities) | |
# Evaluate the expected utility of the simulations | |
expected_utility = expected_utility_logarithmic(simulations) | |
print(f'Expected Utility: {expected_utility}') |
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
def utility_logarithmic(wealth, a=1): | |
return a * np.log(wealth) | |
wealth = np.linspace(1, 100, 100) # Wealth values from 1 to 100 | |
utility = utility_logarithmic(wealth) | |
plt.plot(wealth, utility) | |
plt.xlabel('Wealth') | |
plt.ylabel('Utility') | |
plt.title('Logarithmic Utility Function') |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
def simulate_game(): | |
tosses = 0 | |
while np.random.choice(['H', 'T']) == 'T': | |
tosses += 1 | |
return 2**(tosses + 1) | |
# Simulate the game 10,000 times to approximate the expected payoff |
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
def gaussian_prior(mean: float, std: float) -> Callable[[int], float]: | |
""" | |
Create a Gaussian prior distribution centered around the mean. | |
Parameters: | |
- mean (float): The mean of the Gaussian distribution | |
- std (float): The standard deviation of the Gaussian distribution | |
Returns: | |
- Callable[[int], float]: A function representing the Gaussian prior |
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
from scipy import stats | |
import numpy as np | |
def remove_outliers(data: List[float], threshold: float = 1.5) -> List[float]: | |
""" | |
Remove outliers from the data using the Z-score method. | |
Parameters: | |
- data (List[float]): The observed data | |
- threshold (float): The Z-score threshold for outlier detection |
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
from typing import Callable, List, Tuple | |
import numpy as np | |
from scipy.stats import norm | |
class SegmentChangePointDetector: | |
def __init__(self, prior: Callable[[int], float]) -> None: | |
""" | |
Initialize the SegmentChangePointDetector model. | |
Parameters: |
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
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout | |
def build_advanced_cnn(input_shape): | |
""" | |
Build an advanced CNN model with dropout layers. | |
Parameters: | |
input_shape (tuple): Shape of input images. |
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
import numpy as np | |
from sklearn.model_selection import train_test_split | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import LSTM, Dense | |
def preprocess_data(X_raw): | |
""" | |
Normalize the raw data for LSTM processing. | |
Parameters: |
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
import numpy as np | |
import tensorflow as tf | |
def preprocess_data(X_raw): | |
""" | |
Preprocess the raw data for model training. | |
Parameters: | |
X_raw (array): The raw feature set. | |
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
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense | |
def build_cnn(input_shape): | |
""" | |
Build a Convolutional Neural Network (CNN) for medical imaging. | |
Parameters: | |
input_shape (tuple): The shape of input images. | |
NewerOlder