1
00:00:00,150 --> 00:00:08,370
So as you've seen, the coat basically works, it's helped to order the randomly generated structure

2
00:00:08,850 --> 00:00:16,470
and we got a structure that was pretty much ordered and neighboring spins are almost parallel to each

3
00:00:16,470 --> 00:00:16,800
other.

4
00:00:17,250 --> 00:00:19,110
But there are also some problems.

5
00:00:19,110 --> 00:00:23,610
You see, this is really not a ferromagnetic yet, even though we are getting closer and closer.

6
00:00:24,390 --> 00:00:31,260
So options would be to increase the number of steps or decrease the size of the of the sample.

7
00:00:31,530 --> 00:00:37,590
So on a number of the moments that we consider, but still, there's always the problem that we may

8
00:00:37,590 --> 00:00:39,930
get stuck in some local energy minimum.

9
00:00:39,930 --> 00:00:46,500
And the problem really is that we do not accept any increase in the energy.

10
00:00:47,280 --> 00:00:53,730
This means if we are trapped inside some local energy minimum, there's really no way to get out of

11
00:00:53,730 --> 00:00:53,940
it.

12
00:00:54,360 --> 00:01:01,530
For example, if you imagine you go hiking and you see a valley and you want to go to the closest valley

13
00:01:02,340 --> 00:01:04,560
and you are only allowed to go down.

14
00:01:05,099 --> 00:01:10,290
So this means you can never get out of your valley to get to a next valley, which may be even lower

15
00:01:10,290 --> 00:01:10,830
in height.

16
00:01:11,730 --> 00:01:18,870
And this the same problem here, so we must allow the codes to sometimes increase the energy to help

17
00:01:18,870 --> 00:01:20,220
us get out of such a valley.

18
00:01:20,940 --> 00:01:22,620
And this is one update one means.

19
00:01:23,310 --> 00:01:27,630
And this, in a physical sense, corresponds to considering finite temperatures.

20
00:01:28,680 --> 00:01:35,390
So this means or when you think about it, the temperature is just some thermal fluctuations, just

21
00:01:35,400 --> 00:01:41,280
some random motion of particles or some random or reorientation of our magnetic moments.

22
00:01:42,240 --> 00:01:45,340
So this means it has a particular energy.

23
00:01:45,360 --> 00:01:48,540
This is corresponding to this Boltzmann constant KB.

24
00:01:49,410 --> 00:01:56,670
And very often you see these Boltzmann factors here, such exponential functions where you compare one

25
00:01:56,670 --> 00:01:59,730
energy with another energy, which will be the thermal energy.

26
00:02:00,480 --> 00:02:08,880
So what we do is we still accept every update in the configuration when the energy is decreased and

27
00:02:08,880 --> 00:02:15,000
we sometimes even accept and change in the magnetization when the energy is increased.

28
00:02:16,050 --> 00:02:18,570
So let me copy this code here.

29
00:02:18,720 --> 00:02:22,050
We want to keep it just for completeness.

30
00:02:22,530 --> 00:02:27,660
I will write it here and call this routine step exchange tea for temperature.

31
00:02:28,170 --> 00:02:34,980
And we will give it another parameter, which will be the CCB kbe temperature.

32
00:02:36,720 --> 00:02:39,270
OK, and now we must implement that.

33
00:02:39,270 --> 00:02:48,450
We accept the change even if the energy increases with a chance that is given by this factor here.

34
00:02:49,590 --> 00:02:52,590
So basically, we must change this code here.

35
00:02:53,310 --> 00:02:55,380
So we need another if statement.

36
00:02:56,040 --> 00:02:57,870
We need if.

37
00:02:59,930 --> 00:03:09,500
A randomly generated number, if not random, thought rent is smaller than this exponential exponential

38
00:03:09,500 --> 00:03:10,190
factor here.

39
00:03:10,670 --> 00:03:13,250
So NPR dot expect.

40
00:03:16,380 --> 00:03:27,590
Minus energy, new minus energy holds divided by K B temp.

41
00:03:29,550 --> 00:03:37,830
So if this is true, if this random randomly generated number between zero and one is smaller than this

42
00:03:37,830 --> 00:03:38,280
term.

43
00:03:40,540 --> 00:03:51,650
Then we will still accept the change so that we accept the change and update the energy as before so

44
00:03:51,700 --> 00:04:04,030
we can copy this line of code and if not, so this means if the energy change is positive and if the

45
00:04:04,030 --> 00:04:08,830
random number is larger than this factor, which is basically always the case.

46
00:04:09,100 --> 00:04:14,170
If the energy change here is very large, then we will decline.

47
00:04:14,710 --> 00:04:20,110
So then we will do what we did before, and I think that's really all we have to change here.

48
00:04:20,200 --> 00:04:26,440
We just included this additional if statement with the random number that's smaller than this exponential

49
00:04:26,440 --> 00:04:26,920
factor.

50
00:04:27,310 --> 00:04:33,850
If it's true, we still accept, and if not, then we decline as before so we cannot run this.

51
00:04:34,000 --> 00:04:39,430
Or we will later rerun the whole code, I would say, and we can now change this one here.

52
00:04:39,760 --> 00:04:51,280
We can just say, OK, this one was our initial code, initial version, zero temperature, and now

53
00:04:51,280 --> 00:04:52,690
we write.

54
00:04:56,200 --> 00:05:00,880
That we use this function here and we need to temperature.

55
00:05:01,090 --> 00:05:13,300
So we could, for example, write KBE temp and KBE temp would be, for example, 0.01.

56
00:05:13,900 --> 00:05:16,810
So I think it works best if this value is pretty small.

57
00:05:16,840 --> 00:05:20,740
I tested this a bit before, so let's see if it works this time.

58
00:05:21,550 --> 00:05:22,960
And then we can comment here.

59
00:05:22,960 --> 00:05:25,570
This would be update one.

60
00:05:27,070 --> 00:05:30,430
Consider finite temperatures.

61
00:05:34,680 --> 00:05:42,270
OK, so now I will restart and rerun everything, and then we will see what will be the result.

62
00:05:42,300 --> 00:05:47,400
First of all, I hope that we do not encounter any error, but here it is again already.

63
00:05:47,400 --> 00:05:48,480
So no error yet.

64
00:05:48,960 --> 00:05:50,130
There's one looks also good.

65
00:05:50,430 --> 00:05:51,720
Let's wait a bit longer.

66
00:05:53,250 --> 00:05:55,170
So you see, we didn't really change that much.

67
00:05:55,180 --> 00:06:00,060
We just changed this one, basically, and we changed this one.

68
00:06:00,330 --> 00:06:01,770
The rest is really the same.

69
00:06:02,970 --> 00:06:11,970
And now we see still the energy decreases, even though sometimes it is allowed to increase.

70
00:06:11,970 --> 00:06:14,280
But it happens not very often.

71
00:06:14,280 --> 00:06:15,700
So we don't really see it here.

72
00:06:15,700 --> 00:06:16,710
And that's the whole trick.

73
00:06:18,420 --> 00:06:25,290
It should encounter only a few times, but it should help us to not get stuck in any energy minimum.

74
00:06:26,190 --> 00:06:26,880
Let's see.

75
00:06:27,420 --> 00:06:29,700
Oh, I think this looks pretty good.

76
00:06:29,700 --> 00:06:34,980
If we would just continue to simulate this, then I think we would get to the correct result because

77
00:06:34,980 --> 00:06:38,220
there is no really no rural yet.

78
00:06:38,550 --> 00:06:43,740
So I would say I will just crank it up here to five million.

79
00:06:43,770 --> 00:06:47,310
And when it's finished, I'll get back to you and show you the result.

80
00:06:47,700 --> 00:06:53,660
So I just tried this a few times and I noticed sometimes it got a bit better, but never really perfect.

81
00:06:53,670 --> 00:07:00,210
And so what I did now is I increased the temperature from 0.01 to 0.1.

82
00:07:00,720 --> 00:07:06,030
And you see in the energy now, that's really sometimes the energy now increase this and this is really

83
00:07:06,030 --> 00:07:06,690
what we want.

84
00:07:07,020 --> 00:07:13,950
So you see this nice fluctuation that here you see exactly why we added this, because if we would not

85
00:07:13,950 --> 00:07:19,470
have allowed for the increase of the energy, then maybe the system would have been stuck in this state

86
00:07:19,470 --> 00:07:20,670
for quite a long time.

87
00:07:20,670 --> 00:07:26,520
But then here, due to the increase of the energy, it allows it to get rid of this local minimum and

88
00:07:27,180 --> 00:07:28,380
go deeper in energy.

89
00:07:29,490 --> 00:07:35,760
So the total configuration now looks like this, which looks kind of like a ferromagnetic magnet.

90
00:07:35,760 --> 00:07:40,620
But you also see, of course, the effect of the thermal fluctuation here.

91
00:07:41,130 --> 00:07:45,150
So you see that now the temperature is maybe a bit too high.

92
00:07:45,480 --> 00:07:47,910
And so now you don't get the perfect ferromagnetic.

93
00:07:48,360 --> 00:07:55,290
But I think this is really what I wanted to show you here, and that's really just a good result.

94
00:07:55,290 --> 00:07:58,950
I would say it's it clearly resembles a thorough magnet.

95
00:07:59,910 --> 00:08:05,730
Another trick that we could do and that we will use later on is that we can, of course, also dynamically

96
00:08:05,730 --> 00:08:07,740
change the temperature.

97
00:08:08,220 --> 00:08:17,730
So we could see, for example, that we do not specify here a fixed temperature, but we see that the

98
00:08:17,730 --> 00:08:20,400
temperature updates in every step.

99
00:08:21,060 --> 00:08:28,080
So we could say we start with 0.01 and then we go one minus

100
00:08:30,840 --> 00:08:33,539
no steps.

101
00:08:37,020 --> 00:08:39,480
Basically, the index idolised by a number of steps.

102
00:08:39,600 --> 00:08:40,200
Exactly.

103
00:08:40,679 --> 00:08:45,570
So that when I is equal to zero, then we have a temperature of 0.1.

104
00:08:46,140 --> 00:08:52,290
And when I is equal to the number of steps, so this is the last step, the temperature is then zero.

105
00:08:53,130 --> 00:08:59,340
So maybe we should go here then to zero point two, but I will check and then show you the results later

106
00:08:59,340 --> 00:08:59,520
on.

107
00:08:59,940 --> 00:09:05,700
So really, decreasing the temperature from 0.2 to zero linearly did the trick.

108
00:09:06,240 --> 00:09:12,620
So you see the energy and you see here at the beginning, the temperature is still quite high.

109
00:09:12,810 --> 00:09:19,110
So you often see this increase, which helps to get to low energies very briefly and then the temperature

110
00:09:19,110 --> 00:09:22,890
decreases and you see the fluctuations become weaker and weaker.

111
00:09:23,220 --> 00:09:25,510
And in the end, there is no fluctuation left.

112
00:09:25,590 --> 00:09:34,200
And our result is really a very almost perfect ferromagnetic and a total energy, as I said.

113
00:09:34,560 --> 00:09:37,760
So the expected result would be minus 800.

114
00:09:37,770 --> 00:09:40,410
And so now we are really, really close to this result.

115
00:09:40,920 --> 00:09:42,810
And it worked out pretty well.

116
00:09:43,530 --> 00:09:46,890
So just to come and everything is, of course, based on randomness.

117
00:09:46,890 --> 00:09:52,410
So if you do this simulation, it could happen that you get a different result and that maybe sometimes

118
00:09:52,410 --> 00:09:53,490
it doesn't work so well.

119
00:09:53,850 --> 00:09:58,560
But I think if you rerun the calculations several times and then look at the solution, which gives

120
00:09:58,560 --> 00:10:03,240
you the lowest energy, then this should really give you such a nice ferromagnetic.

