Python Forum
How to do 100 runs simulation based on the current codes?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do 100 runs simulation based on the current codes?
#6
(Sep-03-2023, 02:17 AM)deanhystad Wrote: What do you want to average, acc?
def run_experiment():
    from notears import utils
    # utils.set_random_seed(1) this line cannot be used to ensure different outcomes in each round of the loop
 
    n, d, s0, graph_type, sem_type = 1000, 20, 20, 'ER', 'gauss'
    B_true = utils.simulate_dag(d, s0, graph_type)
    W_true = utils.simulate_parameter(B_true)
    np.savetxt('W_true.csv', W_true, delimiter=',')
 
    X = utils.simulate_linear_sem(W_true, n, sem_type)
    np.savetxt('X.csv', X, delimiter=',')
 
    W_est = notears_linear(X, lambda1=0.1, loss_type='l2')
    assert utils.is_dag(W_est)
    np.savetxt('W_est.csv', W_est, delimiter=',')
    return utils.count_accuracy(B_true, W_est != 0)
 
if __name__ == '__main__':
    acc = [run_experiment() for _ in range(num_experiments)]
    print("Average acc =", sum(acc) / len(acc))
You should not use assert.

Yes, I want to get the average value of acc. The current acc gives me a list like this: {'fdr': 0.0, 'tpr': 0.95, 'fpr': 0.0, 'shd': 1, 'nnz': 19}
Reply


Messages In This Thread
RE: How to do 100 runs simulation based on the current codes? - by dududada - Sep-03-2023, 11:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem program runs in a loop jasserin 0 773 May-18-2024, 03:07 PM
Last Post: jasserin
  Another program runs bho68 7 2,363 Nov-08-2022, 08:16 PM
Last Post: bho68
  How to create an Excel app that runs Python? felipe0216 3 3,007 May-31-2020, 01:19 AM
Last Post: ibutun
  How to execute code WHILE a function runs t4keheart 4 3,905 Jan-27-2020, 01:47 PM
Last Post: t4keheart
  scheduled job only runs once Stan2292 4 3,787 Aug-19-2019, 08:18 AM
Last Post: fishhook
  Stock Rate of Change (based on open and current price) Not Working firebird 1 2,977 Jul-29-2019, 07:10 AM
Last Post: perfringo
  Help with simulation Geeseball 0 2,578 Oct-18-2018, 12:19 PM
Last Post: Geeseball
  Scheduler runs but then fails marciokoko 2 4,886 Jan-19-2017, 12:02 AM
Last Post: marciokoko

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020