質問編集履歴
4
誤字を修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -454,6 +454,8 @@
|
|
454
454
|
|
455
455
|
self.frind_list.append(agent.id)
|
456
456
|
|
457
|
+
agent.hi_friend_list.append(self.id)
|
458
|
+
|
457
459
|
elif self.lc[agent.id] <= -0.04:
|
458
460
|
|
459
461
|
self.exclusion_list.append(agent.id)
|
@@ -470,7 +472,7 @@
|
|
470
472
|
|
471
473
|
def update_f(self,turn): #影響力の更新
|
472
474
|
|
473
|
-
self.s.append(len(self.hi_frind_list)-len(self.hi_exclusion_list))
|
475
|
+
self.s.append(len(self.hi_friend_list)-len(self.hi_exclusion_list))
|
474
476
|
|
475
477
|
dr = rm*(self.s[turn+1]-self.s[turn])
|
476
478
|
|
3
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -194,7 +194,7 @@
|
|
194
194
|
|
195
195
|
h = a*self.lp[agent.id]+b*self.lagent[agent.id]*(1-(self.f-agent.f))+c*(self.f-agent.f)
|
196
196
|
|
197
|
-
h = (h+0.8)/1.6
|
197
|
+
h = (h+0.8)/1.6 #正規化
|
198
198
|
|
199
199
|
z += h
|
200
200
|
|
@@ -206,7 +206,7 @@
|
|
206
206
|
|
207
207
|
h = a*self.lp[agent.id]+b*self.lagent[agent.id]*(1-(self.f-agent.f))+c*(self.f-agent.f)
|
208
208
|
|
209
|
-
h = (h+0.8)/1.6
|
209
|
+
h = (h+0.8)/1.6 #正規化
|
210
210
|
|
211
211
|
weight = h / z
|
212
212
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
シミュレーションの流れは、
|
6
6
|
|
7
|
-
会話相手(1人)の選択→話題対象の選択→好感度の更新(2種類)→関係の構築
|
7
|
+
会話相手(1人)の選択→話題対象の選択→好感度の更新(2種類)→関係の構築
|
8
|
-
|
8
|
+
|
9
|
-
→想像している人間関係の更新
|
9
|
+
→影響力の更新→想像している人間関係の更新
|
10
10
|
|
11
11
|
以上の流れで行います
|
12
12
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
大学の卒業研究でマルチエージェントシミュレーションを用いて学級モデルを構築しています。
|
2
2
|
|
3
|
-
生徒は想像している
|
3
|
+
生徒は想像している人間関係、他の生徒への好感度、クラス内での影響力の3つの設定を持っています。
|
4
4
|
|
5
5
|
シミュレーションの流れは、
|
6
6
|
|
@@ -120,7 +120,7 @@
|
|
120
120
|
|
121
121
|
|
122
122
|
|
123
|
-
def First_set(self,agents):
|
123
|
+
def First_set(self,agents): #初期設定
|
124
124
|
|
125
125
|
issues = 10
|
126
126
|
|
@@ -178,7 +178,7 @@
|
|
178
178
|
|
179
179
|
|
180
180
|
|
181
|
-
def decide_talk_man(self,agents):
|
181
|
+
def decide_talk_man(self,agents): #会話相手の選択
|
182
182
|
|
183
183
|
agents_except_me = {}
|
184
184
|
|
@@ -222,7 +222,7 @@
|
|
222
222
|
|
223
223
|
|
224
224
|
|
225
|
-
def decide_topic(self,agents,talk):
|
225
|
+
def decide_topic(self,agents,talk): #話題対象の選択
|
226
226
|
|
227
227
|
talks = self.talk[0]
|
228
228
|
|
@@ -290,306 +290,306 @@
|
|
290
290
|
|
291
291
|
|
292
292
|
|
293
|
+
for issue in range(issues):
|
294
|
+
|
295
|
+
for agent in agents:
|
296
|
+
|
297
|
+
if agent is self:
|
298
|
+
|
299
|
+
continue
|
300
|
+
|
301
|
+
if agent.id ==talks:
|
302
|
+
|
303
|
+
r = abs(self.lx[issue]*self.f+self.lxagent[issue][agent.id]*talk_f)/zz
|
304
|
+
|
305
|
+
issue += 31
|
306
|
+
|
307
|
+
topic_except_me[issue] = issue
|
308
|
+
|
309
|
+
weights_for_me.append(r)
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
self.topic = random.choices(topic_except_me, weights=weights_for_me)
|
314
|
+
|
315
|
+
print(self.topic)
|
316
|
+
|
317
|
+
return self.topic
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
def update_like1(self,agents,talk,topic): #好感度更新1
|
322
|
+
|
323
|
+
talks = talk[0]
|
324
|
+
|
325
|
+
topics = topic[0]
|
326
|
+
|
327
|
+
if topics <= 30:
|
328
|
+
|
329
|
+
x = self.lp[talks]
|
330
|
+
|
331
|
+
y = self.lp[topics]
|
332
|
+
|
333
|
+
z = self.lpi[talks][topics]
|
334
|
+
|
335
|
+
else:
|
336
|
+
|
337
|
+
topics -= 31
|
338
|
+
|
339
|
+
x = self.lx[topics]
|
340
|
+
|
341
|
+
y = self.lp[talks]
|
342
|
+
|
343
|
+
z = self.lxagent[topics][talks]
|
344
|
+
|
345
|
+
l = x*y*z
|
346
|
+
|
347
|
+
if l>=0:
|
348
|
+
|
349
|
+
dlu1 = gij(y,z,x)
|
350
|
+
|
351
|
+
dlx1 = gij(x,z,y)
|
352
|
+
|
353
|
+
else:
|
354
|
+
|
355
|
+
if x >= y:
|
356
|
+
|
357
|
+
dlu1 = gij(x,z,0)
|
358
|
+
|
359
|
+
dlx1 = 0
|
360
|
+
|
361
|
+
else:
|
362
|
+
|
363
|
+
dlu1 = 0
|
364
|
+
|
365
|
+
dlx1 = gij(y,z,0)
|
366
|
+
|
367
|
+
for agent in agents:
|
368
|
+
|
369
|
+
if agent.id is talks:
|
370
|
+
|
371
|
+
r = w1*self.lp[talks]+w2*self.lagent[talks]*(1-(self.f-agent.f))+w3*(self.f-agent.f)
|
372
|
+
|
373
|
+
r = (r+0.8)/1.6
|
374
|
+
|
375
|
+
break
|
376
|
+
|
377
|
+
weights_for_stra = {r,1-r}
|
378
|
+
|
379
|
+
kinds_of_stra = ["mini","same"]
|
380
|
+
|
381
|
+
stra = random.choices(kinds_of_stra, weights=weights_for_stra)
|
382
|
+
|
383
|
+
if stra is "mini":
|
384
|
+
|
385
|
+
dlu2 = v2*(self.lagent[talks]-self.lp[talks])
|
386
|
+
|
387
|
+
else:
|
388
|
+
|
389
|
+
dlu2 = v3*sign(1,(self.lagent[talks]))*(abs(self.lagent[talks]+self.lp[talks]))
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
dlu = dlu1+dlu2
|
394
|
+
|
395
|
+
dlx = dlx1
|
396
|
+
|
397
|
+
return dlu,dlx
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
def update_like2(self,talk,topic,dlu,dlx): #好感度更新2
|
402
|
+
|
403
|
+
talks = self.talk[0]
|
404
|
+
|
405
|
+
topics = self.topic[0]
|
406
|
+
|
407
|
+
self.lp[talks] = self.lp[talks]+dlu
|
408
|
+
|
409
|
+
self.lc[talks] = self.lp[talks]
|
410
|
+
|
411
|
+
if topics <= 30:
|
412
|
+
|
413
|
+
self.lp[topics] += dlx
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
if self.lp[topics] > 1.0:
|
418
|
+
|
419
|
+
self.lp[topics] = 1.0
|
420
|
+
|
421
|
+
elif self.lp[topics] < -1.0:
|
422
|
+
|
423
|
+
self.lp[topics] = -1.0
|
424
|
+
|
425
|
+
else:
|
426
|
+
|
427
|
+
topics -= 31
|
428
|
+
|
429
|
+
self.lx[topics] += dlx
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
if self.lx[topics] > 1.0:
|
434
|
+
|
435
|
+
self.lx[topics] = 1.0
|
436
|
+
|
437
|
+
elif self.lx[topics] < -1.0:
|
438
|
+
|
439
|
+
self.lx[topics] = -1.0
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
def link(self,agents): #関係の構築
|
446
|
+
|
447
|
+
for agent in agents:
|
448
|
+
|
449
|
+
if agent is self:
|
450
|
+
|
451
|
+
continue
|
452
|
+
|
453
|
+
if self.lc[agent.id] >= 0.12:
|
454
|
+
|
455
|
+
self.frind_list.append(agent.id)
|
456
|
+
|
457
|
+
elif self.lc[agent.id] <= -0.04:
|
458
|
+
|
459
|
+
self.exclusion_list.append(agent.id)
|
460
|
+
|
461
|
+
agent.hi_exclusion_list.append(self.id)
|
462
|
+
|
463
|
+
else:
|
464
|
+
|
465
|
+
pass
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
def update_f(self,turn): #影響力の更新
|
472
|
+
|
473
|
+
self.s.append(len(self.hi_frind_list)-len(self.hi_exclusion_list))
|
474
|
+
|
475
|
+
dr = rm*(self.s[turn+1]-self.s[turn])
|
476
|
+
|
477
|
+
self.f += dr
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
if self.f > 1.0:
|
482
|
+
|
483
|
+
self.f = 1.0
|
484
|
+
|
485
|
+
elif self.f < 0:
|
486
|
+
|
487
|
+
self.f = 0
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
def updete_Pnet(self,agents): #自分が想像している人間関係の更新
|
494
|
+
|
495
|
+
for agent in agents:
|
496
|
+
|
497
|
+
for age in agents:
|
498
|
+
|
499
|
+
if agent is age or self is agent:
|
500
|
+
|
501
|
+
continue
|
502
|
+
|
503
|
+
E = np.random.uniform(low=-0.3, high=0.3, size=None)
|
504
|
+
|
505
|
+
dlp = ap*(agent.lc[age.id]-self.lpi[agent.id][age.id])+E
|
506
|
+
|
507
|
+
self.lpi[agent.id][age.id] += dlp
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
if self.lpi[agent.id][age.id] > 1.0:
|
512
|
+
|
513
|
+
self.lpi[agent.id][age.id] = 1.0
|
514
|
+
|
515
|
+
elif self.lpi[agent.id][age.id] < -1.0:
|
516
|
+
|
517
|
+
self.lpi[agent.id][age.id] = -1.0
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
class Simulation:
|
524
|
+
|
525
|
+
def __init__(self):
|
526
|
+
|
527
|
+
self.agents = []
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
def generate_agents(self, agents_num):
|
532
|
+
|
533
|
+
self.agents = [Agent(agent_id) for agent_id in range(agents_num)]
|
534
|
+
|
535
|
+
for agent in self.agents:
|
536
|
+
|
537
|
+
agent.First_set(self.agents)
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
def play_the_game(self,episode):
|
542
|
+
|
543
|
+
num_agents = 31
|
544
|
+
|
545
|
+
turns = 3000
|
546
|
+
|
547
|
+
self.generate_agents(num_agents)
|
548
|
+
|
549
|
+
for turn in range(turns):
|
550
|
+
|
551
|
+
print(turn,"ターン目")
|
552
|
+
|
553
|
+
for agent in self.agents:
|
554
|
+
|
555
|
+
print(agent)
|
556
|
+
|
557
|
+
self.talk = agent.decide_talk_man(self.agents)
|
558
|
+
|
559
|
+
self.topic = agent.decide_topic(self.agents,self.talk)
|
560
|
+
|
561
|
+
dlu,dlx = agent.update_like1(self.agents,self.talk,self.topic)
|
562
|
+
|
563
|
+
agent.update_like2(self.talk,self.topic,dlu,dlx)
|
564
|
+
|
565
|
+
agent.link(self.agents)
|
566
|
+
|
567
|
+
agent.update_f(turn)
|
568
|
+
|
569
|
+
agent.updete_Pnet(self.agents)
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
simulation = Simulation()
|
580
|
+
|
581
|
+
simulation.play_the_game(31)
|
582
|
+
|
583
|
+
for agent in simulation.agents:
|
584
|
+
|
585
|
+
print("Likabilities for Agent", agent.id, ":")
|
586
|
+
|
587
|
+
for agent_id in agent.lc:
|
588
|
+
|
589
|
+
print(" agent", agent_id, ":", agent.lc[agent_id])
|
590
|
+
|
293
591
|
for issue in range(issues):
|
294
592
|
|
295
|
-
for agent in agents:
|
296
|
-
|
297
|
-
if agent is self:
|
298
|
-
|
299
|
-
continue
|
300
|
-
|
301
|
-
if agent.id ==talks:
|
302
|
-
|
303
|
-
r = abs(self.lx[issue]*self.f+self.lxagent[issue][agent.id]*talk_f)/zz
|
304
|
-
|
305
|
-
issue += 31
|
306
|
-
|
307
|
-
topic_except_me[issue] = issue
|
308
|
-
|
309
|
-
weights_for_me.append(r)
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
self.topic = random.choices(topic_except_me, weights=weights_for_me)
|
314
|
-
|
315
|
-
print(self.topic)
|
316
|
-
|
317
|
-
return self.topic
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
def update_like1(self,agents,talk,topic):
|
322
|
-
|
323
|
-
talks = talk[0]
|
324
|
-
|
325
|
-
topics = topic[0]
|
326
|
-
|
327
|
-
if topics <= 30:
|
328
|
-
|
329
|
-
x = self.lp[talks]
|
330
|
-
|
331
|
-
y = self.lp[topics]
|
332
|
-
|
333
|
-
z = self.lpi[talks][topics]
|
334
|
-
|
335
|
-
else:
|
336
|
-
|
337
|
-
topics -= 31
|
338
|
-
|
339
|
-
x = self.lx[topics]
|
340
|
-
|
341
|
-
y = self.lp[talks]
|
342
|
-
|
343
|
-
z = self.lxagent[topics][talks]
|
344
|
-
|
345
|
-
l = x*y*z
|
346
|
-
|
347
|
-
if l>=0:
|
348
|
-
|
349
|
-
dlu1 = gij(y,z,x)
|
350
|
-
|
351
|
-
dlx1 = gij(x,z,y)
|
352
|
-
|
353
|
-
else:
|
354
|
-
|
355
|
-
if x >= y:
|
356
|
-
|
357
|
-
dlu1 = gij(x,z,0)
|
358
|
-
|
359
|
-
dlx1 = 0
|
360
|
-
|
361
|
-
else:
|
362
|
-
|
363
|
-
dlu1 = 0
|
364
|
-
|
365
|
-
dlx1 = gij(y,z,0)
|
366
|
-
|
367
|
-
for agent in agents:
|
368
|
-
|
369
|
-
if agent.id is talks:
|
370
|
-
|
371
|
-
r = w1*self.lp[talks]+w2*self.lagent[talks]*(1-(self.f-agent.f))+w3*(self.f-agent.f)
|
372
|
-
|
373
|
-
r = (r+0.8)/1.6
|
374
|
-
|
375
|
-
break
|
376
|
-
|
377
|
-
weights_for_stra = {r,1-r}
|
378
|
-
|
379
|
-
kinds_of_stra = ["mini","same"]
|
380
|
-
|
381
|
-
stra = random.choices(kinds_of_stra, weights=weights_for_stra)
|
382
|
-
|
383
|
-
if stra is "mini":
|
384
|
-
|
385
|
-
dlu2 = v2*(self.lagent[talks]-self.lp[talks])
|
386
|
-
|
387
|
-
else:
|
388
|
-
|
389
|
-
dlu2 = v3*sign(1,(self.lagent[talks]))*(abs(self.lagent[talks]+self.lp[talks]))
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
dlu = dlu1+dlu2
|
394
|
-
|
395
|
-
dlx = dlx1
|
396
|
-
|
397
|
-
return dlu,dlx
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
def update_like2(self,talk,topic,dlu,dlx):
|
402
|
-
|
403
|
-
talks = self.talk[0]
|
404
|
-
|
405
|
-
topics = self.topic[0]
|
406
|
-
|
407
|
-
self.lp[talks] = self.lp[talks]+dlu
|
408
|
-
|
409
|
-
self.lc[talks] = self.lp[talks]
|
410
|
-
|
411
|
-
if topics <= 30:
|
412
|
-
|
413
|
-
self.lp[topics] += dlx
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
if self.lp[topics] > 1.0:
|
418
|
-
|
419
|
-
self.lp[topics] = 1.0
|
420
|
-
|
421
|
-
elif self.lp[topics] < -1.0:
|
422
|
-
|
423
|
-
self.lp[topics] = -1.0
|
424
|
-
|
425
|
-
else:
|
426
|
-
|
427
|
-
topics -= 31
|
428
|
-
|
429
|
-
self.lx[topics] += dlx
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
if self.lx[topics] > 1.0:
|
434
|
-
|
435
|
-
self.lx[topics] = 1.0
|
436
|
-
|
437
|
-
elif self.lx[topics] < -1.0:
|
438
|
-
|
439
|
-
self.lx[topics] = -1.0
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
def link(self,agents):
|
446
|
-
|
447
|
-
for agent in agents:
|
448
|
-
|
449
|
-
if agent is self:
|
450
|
-
|
451
|
-
continue
|
452
|
-
|
453
|
-
if self.lc[agent.id] >= 0.12:
|
454
|
-
|
455
|
-
self.frind_list.append(agent.id)
|
456
|
-
|
457
|
-
elif self.lc[agent.id] <= -0.04:
|
458
|
-
|
459
|
-
self.exclusion_list.append(agent.id)
|
460
|
-
|
461
|
-
agent.hi_exclusion_list.append(self.id)
|
462
|
-
|
463
|
-
else:
|
464
|
-
|
465
|
-
pass
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
def update_f(self,turn):
|
472
|
-
|
473
|
-
self.s.append(len(self.hi_frind_list)-len(self.hi_exclusion_list))
|
474
|
-
|
475
|
-
dr = rm*(self.s[turn+1]-self.s[turn])
|
476
|
-
|
477
|
-
self.f += dr
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
if self.f > 1.0:
|
482
|
-
|
483
|
-
self.f = 1.0
|
484
|
-
|
485
|
-
elif self.f < 0:
|
486
|
-
|
487
|
-
self.f = 0
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
def updete_Pnet(self,agents):
|
494
|
-
|
495
|
-
for agent in agents:
|
496
|
-
|
497
|
-
for age in agents:
|
498
|
-
|
499
|
-
if agent is age or self is agent:
|
500
|
-
|
501
|
-
continue
|
502
|
-
|
503
|
-
E = np.random.uniform(low=-0.3, high=0.3, size=None)
|
504
|
-
|
505
|
-
dlp = ap*(agent.lc[age.id]-self.lpi[agent.id][age.id])+E
|
506
|
-
|
507
|
-
self.lpi[agent.id][age.id] += dlp
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
if self.lpi[agent.id][age.id] > 1.0:
|
512
|
-
|
513
|
-
self.lpi[agent.id][age.id] = 1.0
|
514
|
-
|
515
|
-
elif self.lpi[agent.id][age.id] < -1.0:
|
516
|
-
|
517
|
-
self.lpi[agent.id][age.id] = -1.0
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
class Simulation:
|
524
|
-
|
525
|
-
def __init__(self):
|
526
|
-
|
527
|
-
self.agents = []
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
def generate_agents(self, agents_num):
|
532
|
-
|
533
|
-
self.agents = [Agent(agent_id) for agent_id in range(agents_num)]
|
534
|
-
|
535
|
-
for agent in self.agents:
|
536
|
-
|
537
|
-
agent.First_set(self.agents)
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
def play_the_game(self,episode):
|
542
|
-
|
543
|
-
num_agents = 31
|
544
|
-
|
545
|
-
turns = 3000
|
546
|
-
|
547
|
-
self.generate_agents(num_agents)
|
548
|
-
|
549
|
-
for turn in range(turns):
|
550
|
-
|
551
|
-
print(turn,"ターン目")
|
552
|
-
|
553
|
-
for agent in self.agents:
|
554
|
-
|
555
|
-
print(agent)
|
556
|
-
|
557
|
-
self.talk = agent.decide_talk_man(self.agents)
|
558
|
-
|
559
|
-
self.topic = agent.decide_topic(self.agents,self.talk)
|
560
|
-
|
561
|
-
dlu,dlx = agent.update_like1(self.agents,self.talk,self.topic)
|
562
|
-
|
563
|
-
agent.update_like2(self.talk,self.topic,dlu,dlx)
|
564
|
-
|
565
|
-
agent.link(self.agents)
|
566
|
-
|
567
|
-
agent.update_f(turn)
|
568
|
-
|
569
|
-
agent.updete_Pnet(self.agents)
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
simulation = Simulation()
|
580
|
-
|
581
|
-
simulation.play_the_game(31)
|
582
|
-
|
583
|
-
for agent in simulation.agents:
|
584
|
-
|
585
|
-
print("Likabilities for Agent", agent.id, ":")
|
586
|
-
|
587
|
-
for agent_id in agent.lc:
|
588
|
-
|
589
|
-
print(" agent", agent_id, ":", agent.lc[agent_id])
|
590
|
-
|
591
|
-
for issue in range(issues):
|
592
|
-
|
593
593
|
print(" issue", issue, ":", agent.lx[issue])
|
594
594
|
|
595
595
|
print(" frind", ":", agent.frlist)
|