U

@umorzy

HW 1 def

R
1 year ago
# Impostazione del seme set.seed(345857) # ESERCIZIO 1 # Parametri a <- runif(1, min = 2.5, max = 5.5) # parametro 'a' estratto da U(2.5, 5.5) b <- 1 # parametro 'b' p <- 0.5 # probabilità per Bernoulli

HW1 ES 2

R
1 year ago
# Parametri dati dall'esercizio set.seed(345857) # Imposta un seed per riproducibilità mu <- runif(1, -1.5, 1.5) # Simula mu da U(-1.5, 1.5) sigma2 <- runif(1, 0.5, 1.5) # Simula sigma^2 da U(0.5, 1.5) sigma <- sqrt(sigma2) # Deviazione standard # Funzione di densità logistic-normal logistic_normal_density <- function(x, mu, sigma2) { (1 / (x * (1 - x) * sqrt(2 * pi * sigma2))) * exp(-0.5 * ((log(x / (1 - x)) - mu)^2 / sigma2))

HM1 ES 1

R
1 year ago
# Impostazione del seme set.seed(345857) # Parametri a <- runif(1, min = 2.5, max = 5.5) # parametro 'a' estratto da U(2.5, 5.5) b <- 1 # parametro 'b' p <- 0.5 # probabilità per Bernoulli lambda <- runif(1, min = 2, max = 4) # parametro 'lambda' estratto da U(2, 4) xseq = seq(0, 15, by=0.001) n_samples <- 10000 # numero di campioni Monte Carlo

jags normal

R
1 year ago
# -------------------------- # ESERCITAZIONE 3 # Normal Inference (RJags) # -------------------------- library(R2jags) library(rjags)

jags hierarchical

R
1 year ago
# ------------------------------ # ESERCITAZIONE 3 # Hierarchical Model (RJags) # ------------------------------ # In order to understand how many resources to allocate for next # year (rooms, canteens ...) a university needs to make a prediction # on how many students will pass the admission test next year. # In order to do so, the university relies on some data collected # this year, in particular the score (pass/not pass) of each student

Ese 2 1.4 start

R
1 year ago
a = 3 b = 10 par(mfrow=c(2,2)) for(m in c(10,20,100,1000)) { c = 1/m xdom = c(0:(m-1))/m +c/2 x_start = xdom - c/2 x_end = xdom + c/2 prob_x = dbeta(xdom ,a,b)

eq secondo grado

Python
2 years ago
#siano a, b, c i coefficienti di un polinomio di secondo grado p(n) = ax^2 + bx + c from math import sqrt a = int(input()) b = int(input()) c = int(input()) A = str(a) B = str(b) C = str(c)

fattorizzazione

Python
2 years ago
from sys import exit def fattorizzazione(): inserimento = input() if not inserimento.isdigit(): exit("ERRORE: NON È STATO INSERITO UN INTERO!") #controllo dell'input else: n = int(inserimento)

numeri primi

Python
2 years ago
def lista_n_primi(): A = int(input()) vettore_n_primi = [2] print() for a in range (3, A + 1): i = 2 while i <= a / 2 and a % i != 0: i = i +1

Cesare

Python
2 years ago
def CifrarioCesare(): cambio = int(input()) testo = input().upper() lista = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' for i in range(len(testo)): if testo != ' ': for k in range(len(lista)): if testo[i] == lista[k]: testo = testo[:i] + lista[k + cambio] + testo[i+1:] break

Fibonacci

Python
2 years ago
def Fibonacci(): n = int(input()) listaFib = [0, 1] if n >= 3: for i in range (n-2): l = len(listaFib) listaFib.append(listaFib[l-1] + listaFib[l-2]) print(listaFib[n-1]) return listaFib

Check Anagrammi

Python
2 years ago
# data una stringa ci itero sopra e vedo se ho un elemento uguale nell'altra, e allora lo rimuovo dall'altra def rimozioneSpazi(str): i = 0 while i < len(str): if str[i] == ' ': str = str[:i] + str[i + 1:] else: i += 1

cambio di base

Python
2 years ago
def to_bin(): n = int(input()) lista = [] i = 1 while i <= n: lista.insert(0, i) i *= 2 soluzione = '' for k in lista: