Chủ Nhật, 8 tháng 3, 2020

KỸ NĂNG NÀO BẢN THÂN CẦN RÈN LUYỆN CHO NĂM 2020?

KỸ NĂNG VIẾT

NHẬN THỨC <=> HÀNH VI: Có rất nhiều kỹ năng cần được rèn luyện sau khi trang bị nhận thức đúng đắng hoặc là chấp nhận rủi ro cao => mất mát lớn sau hành vi sai nhưng đổi lại thứ nhận được là một nhận thức ăn sâu vào bộ não trong thời gian dài.

Đẳng cấp giải quyết khi đứng trước một vấn đề/hiện tượng được chia làm nhiều cấp độ:
Biết -> Hiểu -> Làm -> Phân tích -> Tổng hợp -> Sáng tạo.
Tùy vào cấp độ thì hiệu quả công việc đạt được cũng khác nhau, cấp độ tổng hợp là level mà mình hướng đến trong năm 2020. Phải thật thuần thục nó! Để thực hiện được điều đó thì sẽ có một chùm kỹ năng nhỏ khác cần được thực hành thường xuyên trong đó có kỹ năng viết.

Các lợi ích của kỹ năng viết:
- Rèn tính rành mạch: cách sắp xếp luận điểm, luận cứ khi trình bày một vấn đề phần quan trọng hơn nội dung trình bày. Làm cho người nghe dễ dàng tiếp thu, không mất quá nhiều sức/thời gian để hiểu được vấn đề. Mang cảm giác dễ chịu, tích cực cho người nhận.
- Rèn tính tổng hợp thông tin từ nhiều nơi, nhiều thời điểm được lưu trữ trong não bộ: trong lĩnh vực trí tuệ nhân tạo có khái niệm feature, tức các yếu tố ành hưởng đến quyết định của AI. Rõ rành để có thông tin đầy đủ ta phải có cách truy xuất sao cho hiểu quả nhất. Điều đó cần được rèn luyện hàng ngày.
- Rèn tính cẩn thận: điều đơn giản mang lại hiệu quả cao nhưng lại thuộc nhóm kỹ năng khó làm vì các hành vi nhỏ thường rơi vào nhóm quản trị chính bản thân mình. Quản trị bản thân là quản trị khó nhất trong các nhóm quản trị.

Các chủ đề viết lần sau: các khái niệm kinh tế mới (nghe/nói/nghĩ/làm, xuyên môn hóa, không còn khái niệm thị trường là chiến trường ), AI, các recommender system ngu ngốc như thế nào, chém gió hay làm gió.
Đọc tiếp »

Thứ Tư, 6 tháng 11, 2019

16 Khái niệm JavaScript phải biết! (series)

Mở đầu, trong js có data type cơ bản nhất là đó là object data type và nó có 5 loại cơ bản là number, string, boolean, undefined và null. chúng còn được gọi là primitive data types(giá trị của chúng không thể bị thay đổi, mỗi lần thay đổi tức là địa chỉ vùng nhớ đã thay đổi => gọi chúng immutable)

What is object?
Object là tập hợp danh sách primitive data types (hoặc reference data types) mà ta không quan tâm đến thứ tự của chúng. mỗi item trong danh sách này là 1 cặp name-value. mỗi item được gọi là property (nếu item ấy là function thì gọi là method)

var taibn1={lastName:'Bui', age:23};

giải thích: lastName:'Bui' và  age:23 là property. mỗi property có tên lần lượt là lastName, age và các giá trị lần lượt là Bui và 23

Reference data type and primitive data types
một trong những điểm khác nhau chính giữa 2 data type trên là giá trị của reference data type thì được lưu trữ như một tham chiếu tức là giá trị của nó không được lưu trữ trực tiếp trên biến như primitive data types.

// primitive
var woman="advanced women";
var anotherWoman=woman;
woman="available women";

console.log(anotherWoman);// woman
console.loog(woman);// available women

ta thấy rằng biến giá trị mà biến anottherWoman mang là 1 bản copy giá trị của biến woman và 2 biến này có vùng nhớ biến và vùng nhớ để chứa giá trị mang là riêng biệt.

//Reference
thôi đi ngủ - mai viết: dễ hiểu nhất là liên tưởng đến con trỏ trong nn C/C++

Đọc tiếp »

Thứ Bảy, 26 tháng 1, 2019

The liberal phoenix ( phượng hoàng tự do )

This is not the first time the liberal story has faced a crisis of confidence. Ever
since this story gained global influence, in the second half of the nineteenth
century, it has endured periodic crises. The first era of globalisation and
liberalisation ended in the bloodbath of the First World War, when imperial
power politics cut short the global march of progress. In the days following
the murder of Archduke Franz Ferdinand in Sarajevo it turned out that the
great powers believed in imperialism far more than in liberalism, and instead
of uniting the world through free and peaceful commerce they focused on
conquering a bigger slice of the globe by brute force. Yet liberalism survived
this Franz Ferdinand moment and emerged from the maelstrom stronger than
before, promising that this was ‘the war to end all wars’. Allegedly, the
unprecedented butchery had taught humankind the terrible price of
imperialism, and now humanity was finally ready to create a new world order
based on the principles of freedom and peace.


Then came the Hitler moment, when, in the 1930s and early 1940s, fascism
seemed for a while irresistible. Victory over this threat merely ushered in the
next. During the Che Guevara moment, between the 1950s and the 1970s, it
again seemed that liberalism was on its last legs, and that the future belonged
to communism. In the end it was communism that collapsed. The supermarket
proved to be far stronger than the Gulag. More importantly, the liberal story
proved to be far more supple and dynamic than any of its opponents. It
triumphed over imperialism, over fascism, and over communism by adopting
some of their best ideas and practices. In particular, the liberal story learned
from communism to expand the circle of empathy and to value equality
alongside liberty.

In the beginning, the liberal story cared mainly about the liberties and
privileges of middle-class European men, and seemed blind to the plight of
working-class people, women, minorities and non-Westerners. When in 1918
victorious Britain and France talked excitedly about liberty, they were not
thinking about the subjects of their worldwide empires. For example, Indian
demands for self-determination were answered by the Amritsar massacre of
1919, in which the British army killed hundreds of unarmed demonstrators.

Even in the wake of the Second World War, Western liberals still had a very
hard time applying their supposedly universal values to non-Western people.
Thus when the Dutch emerged in 1945 from five years of brutal Nazi
occupation, almost the first thing they did was raise an army and send it
halfway across the world to reoccupy their former colony of Indonesia.
Whereas in 1940 the Dutch gave up their own independence after little more
than four days of fighting, they fought for more than four long and bitter years
to suppress Indonesian independence. No wonder that many national
liberation movements throughout the world placed their hopes on communist
Moscow and Beijing rather than on the self-proclaimed champions of liberty
in the West.

Gradually, however, the liberal story expanded its horizons, and at least in
theory came to value the liberties and rights of all human beings without
exception. As the circle of liberty expanded, the liberal story also came to
recognise the importance of communist-style welfare programmes. Liberty is
not worth much unless it is coupled with some kind of social safety net.
Social-democratic welfare states combined democracy and human rights with
state-sponsored education and healthcare. Even the ultra-capitalist USA has
realised that the protection of liberty requires at least some government
welfare services. Starving children have no liberties.


By the early 1990s, thinkers and politicians alike hailed ‘the End of
History’, confidently asserting that all the big political and economic
questions of the past had been settled, and that the refurbished liberal package
of democracy, human rights, free markets and government welfare services
remained the only game in town. This package seemed destined to spread
around the whole world, overcome all obstacles, erase all national borders,
and turn humankind into one free global community.


But history has not ended, and following the Franz Ferdinand moment, the
Hitler moment, and the Che Guevara moment, we now find ourselves in the
Trump moment. This time, however, the liberal story is not faced by a
coherent ideological opponent like imperialism, fascism, or communism. The
Trump moment is far more nihilistic.

Whereas the major movements of the twentieth century all had a vision for
the entire human species – be it global domination, revolution or liberation –
Donald Trump offers no such thing. Just the opposite. His main message is
that it’s not America’s job to formulate and promote any global vision.
Similarly, the British Brexiteers barely have a plan for the future of the
Disunited Kingdom – the future of Europe and of the world is far beyond
their horizon. Most people who voted for Trump and Brexit didn’t reject the
liberal package in its entirety – they lost faith mainly in its globalising part.
They still believe in democracy, free markets, human rights and social
responsibility, but they think these fine ideas can stop at the border. Indeed,
they believe that in order to preserve liberty and prosperity in Yorkshire or
Kentucky, it is best to build a wall on the border, and adopt illiberal policies
towards foreigners.

The rising Chinese superpower presents an almost mirror image. It is wary
of liberalising its domestic politics, but it has adopted a far more liberal
approach to the rest of the world. In fact, when it comes to free trade and
international cooperation, Xi Jinping looks like Obama’s real successor.
Having put Marxism–Leninism on the back burner, China seems rather happy
with the liberal international order.

Resurgent Russia sees itself as a far more forceful rival of the global liberal
order, but though it has reconstituted its military might, it is ideologically
bankrupt. Vladimir Putin is certainly popular both in Russia and among
various right-wing movements across the world, yet he has no global world
view that might attract unemployed Spaniards, disgruntled Brazilians or
starry-eyed students in Cambridge.


Russia does offer an alternative model to liberal democracy, but this model
is not a coherent political ideology. Rather, it is a political practice in which a
number of oligarchs monopolise most of a country’s wealth and power, and
then use their control of the media to hide their activities and cement their
rule. Democracy is based on Abraham Lincoln’s principle that ‘you can fool
all the people some of the time, and some of the people all the time, but you
cannot fool all the people all the time’. If a government is corrupt and fails to
improve people’s lives, enough citizens will eventually realise this and
replace the government. But government control of the media undermines
Lincoln’s logic, because it prevents citizens from realising the truth. Through
its monopoly over the media, the ruling oligarchy can repeatedly blame all its
failures on others, and divert attention to external threats – either real or
imaginary.


When you live under such an oligarchy, there is always some crisis or other
that takes priority over boring stuff such as healthcare and pollution. If the
nation is facing external invasion or diabolical subversion, who has time to
worry about overcrowded hospitals and polluted rivers? By manufacturing a
never-ending stream of crises, a corrupt oligarchy can prolong its rule
indefinitely.

Yet though enduring in practice, this oligarchic model appeals to no one.
Unlike other ideologies that proudly expound their vision, ruling oligarchies
are not proud of their practices, and they tend to use other ideologies as a
smoke screen. Thus Russia pretends to be a democracy, and its leadership
proclaims allegiance to the values of Russian nationalism and Orthodox
Christianity rather than to oligarchy. Right-wing extremists in France and
Britain may well rely on Russian help and express admiration for Putin, but
even their voters would not like to live in a country that actually copies the
Russian model – a country with endemic corruption, malfunctioning services,
no rule of law, and staggering inequality. According to some measures, Russia
is one of the most unequal countries in the world, with 87 per cent of wealth
concentrated in the hands of the richest 10 per cent of people.9 How many
working-class supporters of the Front National want to copy this wealthdistribution
pattern in France?


Humans vote with their feet. In my travels around the world I have met
numerous people in many countries who wish to emigrate to the USA, to
Germany, to Canada or to Australia. I have met a few who want to move to
China or Japan. But I am yet to meet a single person who dreams of
emigrating to Russia.


As for ‘global Islam’, it attracts mainly those who were born in its lap.
While it may appeal to some people in Syria and Iraq, and even to alienated
Muslim youths in Germany and Britain, it is hard to see Greece or South
Africa – not to mention Canada or South Korea – joining a global caliphate as
the remedy to their problems. In this case, too, people vote with their feet. For
every Muslim youth from Germany who travelled to the Middle East to live
under a Muslim theocracy, probably a hundred Middle Eastern youths would
have liked to make the opposite journey, and start a new life for themselves in
liberal Germany.


This might imply that the present crisis of faith is less severe than its
predecessors. Any liberal who is driven to despair by the events of the last
few years should just recollect how much worse things looked in 1918, 1938
or 1968. At the end of the day, humankind won’t abandon the liberal story,
because it doesn’t have any alternative. People may give the system an angry
kick in the stomach but, having nowhere else to go, they will eventually come
back.

Alternatively, people may completely give up on having a global story of
any kind, and instead seek shelter with local nationalist and religious tales. In
the twentieth century, nationalist movements were an extremely important
political player, but they lacked a coherent vision for the future of the world
other than supporting the division of the globe into independent nation states.
Thus Indonesian nationalists fought against Dutch domination, and
Vietnamese nationalists wanted a free Vietnam, but there was no Indonesian
or Vietnamese story for humanity as a whole. When it came time to explain
how Indonesia, Vietnam and all the other free nations should relate to one
another, and how humans should deal with global problems such as the threat
of nuclear war, nationalists invariably turned to either liberal or communist
ideas.

But if both liberalism and communism are now discredited, maybe humans
should abandon the very idea of a single global story? After all, weren’t all
these global stories – even communism – the product of Western imperialism?
Why should Vietnamese villagers put their faith in the brainchild of a German
from Trier and a Manchester industrialist? Maybe each country should adopt
a different idiosyncratic path, defined by its own ancient traditions? Perhaps
even Westerners should take a break from trying to run the world, and focus
on their own affairs for a change?

This is arguably what is happening all over the globe, as the vacuum left by
the breakdown of liberalism is tentatively filled by nostalgic fantasies about
some local golden past. Donald Trump coupled his calls for American
isolationism with a promise to ‘Make America Great Again’ – as if the USA
of the 1980s or 1950s was a perfect society that Americans should somehow
recreate in the twenty-first century. The Brexiteers dream of making Britain
an independent power, as if they were still living in the days of Queen
Victoria and as if ‘splendid isolation’ were a viable policy for the era of the
Internet and global warming. Chinese elites have rediscovered their native
imperial and Confucian legacies, as a supplement or even substitute for the
doubtful Marxist ideology they imported from the West. In Russia, Putin’s
official vision is not to build a corrupt oligarchy, but rather to resurrect the old
tsarist empire. A century after the Bolshevik Revolution, Putin promises a
return to ancient tsarist glories with an autocratic government buoyed by
Russian nationalism and Orthodox piety spreading its might from the Baltic to
the Caucasus.

Similar nostalgic dreams that mix nationalist attachment with religious
traditions underpin regimes in India, Poland, Turkey and numerous other
countries. Nowhere are these fantasies more extreme than in the Middle East,
where Islamists want to copy the system established by the Prophet
Muhammad in the city of Medina 1,400 years ago, while fundamentalist Jews
in Israel outdo even the Islamists, and dream of going back 2,500 years to
biblical times. Members of Israel’s ruling coalition government talk openly
about their hope of expanding modern Israel’s borders to match more closely
those of biblical Israel, of reinstating biblical law, and even of rebuilding the
ancient Temple of Yahweh in Jerusalem in place of the Al-Aqsa mosque

Liberal elites look in horror at these developments, and hope that humanity
will return to the liberal path in time to avert disaster. In his final speech to the
United Nations in September 2016, President Obama warned his listeners
against retreating ‘into a world sharply divided, and ultimately in conflict,
along age-old lines of nation and tribe and race and religion’. Instead, he said,
‘the principles of open markets and accountable governance, of democracy
and human rights and international law … remain the firmest foundation for
human progress in this century’.

Obama has rightly pointed out that despite the numerous shortcomings of
the liberal package, it has a much better record than any of its alternatives.
Most humans never enjoyed greater peace or prosperity than they did under
the aegis of the liberal order of the early twenty-first century. For the first
time in history, infectious diseases kill fewer people than old age, famine kills
fewer people than obesity, and violence kills fewer people than accidents

But liberalism has no obvious answers to the biggest problems we face:
ecological collapse and technological disruption. Liberalism traditionally
relied on economic growth to magically solve difficult social and political
conflicts. Liberalism reconciled the proletariat with the bourgeoisie, the
faithful with the atheists, the natives with the immigrants, and the Europeans
with the Asians by promising everybody a larger slice of the pie. With a
constantly growing pie, that was possible. However, economic growth will
not save the global ecosystem – just the opposite, it is the cause of the
ecological crisis. And economic growth will not solve technological
disruption – it is predicated on the invention of more and more disruptive
technologies.

The liberal story and the logic of free-market capitalism encourage people
to have grand expectations. During the latter part of the twentieth century,
each generation – whether in Houston, Shanghai, Istanbul or São Paulo –
enjoyed better education, superior healthcare and larger incomes than the one
that came before it. In coming decades, however, owing to a combination of
technological disruption and ecological meltdown, the younger generation
might be lucky to just stay in place.

We are consequently left with the task of creating an updated story for the
world. Just as the upheavals of the Industrial Revolution gave birth to the
novel ideologies of the twentieth century, so the coming revolutions in
biotechnology and information technology are likely to require fresh visions.
The next decades might therefore be characterised by intense soul-searching
and by formulating new social and political models. Could liberalism reinvent
itself yet again, just as it did in the wake of the 1930s and 1960s crises,
emerging as more attractive than ever before? Could traditional religion and
nationalism provide the answers that escape the liberals, and could they use
ancient wisdom to fashion an up-to-date world view? Or perhaps the time has
come to make a clean break with the past, and craft a completely new story
that goes beyond not just the old gods and nations, but even the core modern
values of liberty and equality?

At present, humankind is far from reaching any consensus on these
questions. We are still in the nihilist moment of disillusionment and anger,
after people have lost faith in the old stories but before they have embraced a
new one. So what next? The first step is to tone down the prophecies of doom,
and switch from panic mode to bewilderment. Panic is a form of hubris. It
comes from the smug feeling that I know exactly where the world is heading
– down. Bewilderment is more humble, and therefore more clear-sighted. If
you feel like running down the street crying ‘The apocalypse is upon us!’, try
telling yourself ‘No, it’s not that. Truth is, I just don’t understand what’s
going on in the world.’

The following chapters will try to clarify some of the bewildering new
possibilities we face, and how we might proceed from here. But before
exploring potential solutions to humanity’s predicaments we need a better
grasp of the challenge technology poses. The revolutions in information
technology and biotechnology are still in their infancy, and it is debatable to
what extent they are really responsible for the current crisis of liberalism.
Most people in Birmingham, Istanbul, St Petersburg and Mumbai are only
dimly aware, if at all, of the rise of artificial intelligence and its potential
impact on their lives. It is undoubtable, however, that the technological
revolutions will gather momentum in the next few decades, and will confront
humankind with the hardest trials we have ever encountered. Any story that
seeks to gain humanity’s allegiance will be tested above all in its ability to
deal with the twin revolutions in infotech and biotech. If liberalism,
nationalism, Islam or some novel creed wishes to shape the world of the year
2050, it will need not only to make sense of artificial intelligence, Big Data
algorithms and bioengineering – it will also need to incorporate them into a
new meaningful narrative.

To understand the nature of this technological challenge, perhaps it would
be best to start with the job market. Since 2015 I have been travelling around
the world talking with government officials, business people, social activists
and schoolkids about the human predicament. Whenever they become
impatient or bored by all the talk of artificial intelligence, Big Data algorithms
and bioengineering, I usually need to mention just one magic word to snap
them back to attention: jobs. The technological revolution might soon push
billions of humans out of the job market, and create a massive new useless
class, leading to social and political upheavals that no existing ideology
knows how to handle. All the talk about technology and ideology might sound
abstract and remote, but the very real prospect of mass unemployment – or
personal unemployment – leaves nobody indifferent.

28


Đọc tiếp »

From killing mosquitoes to killing thoughts

The sense of disorientation and impending doom is exacerbated by the
accelerating pace of technological disruption. The liberal political system has
been shaped during the industrial era to manage a world of steam engines, oil
refineries and television sets. It finds it difficult to deal with the ongoing
revolutions in information technology and biotechnology.
Both politicians and voters are barely able to comprehend the new
technologies, let alone regulate their explosive potential. Since the 1990s the
Internet has changed the world probably more than any other factor, yet the
Internet revolution was directed by engineers more than by political parties.
Did you ever vote about the Internet? The democratic system is still
struggling to understand what hit it, and is hardly equipped to deal with the
next shocks, such as the rise of AI and the blockchain revolution.


Already today, computers have made the financial system so complicated

that few humans can understand it. As AI improves, we might soon reach a
point when no human can make sense of finance any more. What will that do
to the political process? Can you imagine a government that waits humbly for
an algorithm to approve its budget or its new tax reform? Meanwhile peer-topeer
blockchain networks and cryptocurrencies like bitcoin might completely
revamp the monetary system, so that radical tax reforms will be inevitable.
For example, it might become impossible or irrelevant to tax dollars, because
most transactions will not involve a clear-cut exchange of national currency,
or any currency at all. Governments might therefore need to invent entirely
new taxes – perhaps a tax on information (which will be both the most
important asset in the economy, and the only thing exchanged in numerous
transactions). Will the political system manage to deal with the crisis before it
runs out of money?

Even more importantly, the twin revolutions in infotech and biotech could

restructure not just economies and societies but our very bodies and minds. In
the past, we humans have learned to control the world outside us, but we had
very little control over the world inside us. We knew how to build a dam and
stop a river from flowing, but we did not know how to stop the body from
ageing. We knew how to design an irrigation system, but we had no idea how
to design a brain. If mosquitoes buzzed in our ears and disturbed our sleep,
we knew how to kill the mosquitoes; but if a thought buzzed in our mind and
kept us awake at night, most of us did not know how to kill the thought.

The revolutions in biotech and infotech will give us control of the world

inside us, and will enable us to engineer and manufacture life. We will learn
how to design brains, extend lives, and kill thoughts at our discretion. Nobody
knows what the consequences will be. Humans were always far better at
inventing tools than using them wisely. It is easier to manipulate a river by
building a dam across it than it is to predict all the complex consequences this
will have for the wider ecological system. Similarly, it will be easier to
redirect the flow of our minds than to divine what it will do to our personal
psychology or to our social systems.

In the past, we have gained the power to manipulate the world around us

and to reshape the entire planet, but because we didn’t understand the
complexity of the global ecology, the changes we made inadvertently
disrupted the entire ecological system and now we face an ecological
collapse. In the coming century biotech and infotech will give us the power to
manipulate the world inside us and reshape ourselves, but because we don’t
understand the complexity of our own minds, the changes we will make might
upset our mental system to such an extent that it too might break down.

The revolutions in biotech and infotech are made by engineers,

entrepreneurs and scientists who are hardly aware of the political implications
of their decisions, and who certainly don’t represent anyone. Can parliaments
and parties take matters into their own hands? At present, it does not seem so.
Technological disruption is not even a leading item on the political agenda.
Thus during the 2016 US presidential race, the main reference to disruptive
technology concerned Hillary Clinton’s email debacle,3 and despite all the talk
about job losses, neither candidate addressed the potential impact of
automation. Donald Trump warned voters that the Mexicans and Chinese will
take their jobs, and that they should therefore build a wall on the Mexican
border.4 He never warned voters that the algorithms will take their jobs, nor
did he suggest building a firewall on the border with California.

This might be one of the reasons (though not the only one) why even voters

in the heartlands of the liberal West are losing faith in the liberal story and in
the democratic process. Ordinary people may not understand artificial
intelligence and biotechnology, but they can sense that the future is passing
them by. In 1938 the condition of the common person in the USSR, Germany
or the USA may have been grim, but he was constantly told that he was the
most important thing in the world, and that he was the future (provided, of
course, that he was an ‘ordinary person’ rather than a Jew or an African). He
looked at the propaganda posters – which typically depicted coal miners,
steelworkers and housewives in heroic poses – and saw himself there: ‘I am in
that poster! I am the hero of the future!

In 2018 the common person feels increasingly irrelevant. Lots of

mysterious words are bandied around excitedly in TED talks, government
think tanks and hi-tech conferences – globalisation, blockchain, genetic
engineering, artificial intelligence, machine learning – and common people
may well suspect that none of these words are about them. The liberal story
was the story of ordinary people. How can it remain relevant to a world of
cyborgs and networked algorithms?

In the twentieth century, the masses revolted against exploitation, and

sought to translate their vital role in the economy into political power. Now
the masses fear irrelevance, and they are frantic to use their remaining
political power before it is too late. Brexit and the rise of Trump might thus
demonstrate an opposite trajectory to that of traditional socialist revolutions.
The Russian, Chinese and Cuban revolutions were made by people who were
vital for the economy, but who lacked political power; in 2016, Trump and
Brexit were supported by many people who still enjoyed political power, but
who feared that they were losing their economic worth. Perhaps in the twentyfirst
century populist revolts will be staged not against an economic elite that
exploits people, but against an economic elite that does not need them any
more.6 This may well be a losing battle. It is much harder to struggle against
irrelevance than against exploitation.

Đọc tiếp »

Thứ Hai, 13 tháng 8, 2018

Tabulation And Memozitation [ Dynamic Programming ] [ Set 1 ]

LÝ THUYẾT CƠ SỞ
Có hai cách thức để lưu các value của một problem mà những value này có thể được tái sử dụng.
Ở đây, chúng ta tập trung vào hai mô hình của việc giải quyết problem thông qua dynamic programming. Đó là:
1. Tabulation: Sự sắp xếp thành bảng, cột. Từ dưới lên gọi là bottom up.
2. Memoization: Sự ghi nhớ hay lưu trữ. Từ trên xuống gọi là top down

Trước khi đi đến những định nghĩa của hai mục trên, ta xem xét 2 phát biểu sau:
Version 1: Tôi sẽ học lý thuyết của Quy hoạch động từ blog buingoctai.blogspot.com và sau đó practice vài problem trên đây, dĩ nhiên tôi sẽ trở thành chuyên gia về lập trình quy hoạch động.
Version 2:  Để trở thành một chuyên gia về lập trình quy hoạch động, tôi cần luyện tập giải quyết nhiều problem về quy hoạch động, do đó đầu tiên, tôi cần học lý thuyết về quy hoạch động từ trang buingoctai.blogspot.com.

Cả hai version trên đều giống nhau về mặt nội  dung, chỉ khác nhau về cách truyền đạt lời nhắn trên và đó chính xác là cách làm việc của bottom up và top down.
Version 1 có thể được xem như bottom up và Version 2 được xem như top down.

TABULATION METHOD- BOTTOM UP DYNAMIC PROGRAMMING

Đúng như cái tên của nó, bắt đầu từ đấy và tích lũy câu trả lời đến top.
cùng thảo luận vào những mục của sự chuyển đổi trạng thái.
Ta xem trạng thái cơ sở được gắn liền với dp[0] và trạng thái đích là dp[n]. vì vậy ta cần tìm value của trạng thái đích dp[n]
Cách tiếp cận theo kiểu bottom up là chúng ta bắt đầu sự chuyển đổi từ trạng thái cơ bản bottom và đi đến trạng thái top mong muốn.

 Vậy tại sao ta gọi đó là tabulation method ?
Để hiểu được nó, ta cần viết 1 vài dòng code tinh thừa số của một số sử dụng cách tiếp cận bottom up. Các thủ tục thông thường để solve một DP problem là đầu tiên ta cần định nghĩa một trạng thái.
trong trường hợp này ta định nghĩa 1 trạng thái như 1 dp[x] mà ở đó dp[x] là để tìm thừa số của x.
Rất dễ hiểu rằng dp[x+1]=dp[x]*(x+1). ví dụ tìm giai thừa của 4 thì rõ ràng ta thấy giai thừa của 4= giai thừa của 3  nhân cho 4
implement trong c:






Ở cách tiếp cận theo phương pháp tabulation trên, ta bắt đầu sự chuyển tiếp từ đáy với trạng thái cơ bản là dp[0] và tới trạng thái đích là dp[9]. ở đây chúng ta nhận thấy rằng bảng dp được thêm vào một cách tuần tự và chúng ta truy cập và tính trực tiếp từ bảng đó . Và do đó ta gọi phương pháp này là tabulation ( lập bảng)

MEMOZATION METHOD- TOP DOWN DYNAMIC PROGRAMMING

Phương pháp memozation rất giống với phương pháp chia để trị, tức là ta chi nhỏ bài toán thành các bài toán con, sau đó đi tìm lời giải các bài toán con, để tổng hợp thành lời giải cho bài toán ban đầu. Nhưng khác phương pháp chia để trị ở chỗ là phương pháp này nó giúp ta ghi nhớ lời giải các bài toán con để có thể tái sử dụng chúng cho các problem khác nên nó cũng được gọi là phương pháp ghi nhớ.



Ta thấy rằng lời giải của các bài toán con được lưu vào mảng dp[]

TÓM LẠI: Ý tưởng của quy hoạch động khá đơn giản " mỗi khi tính toán một problem nào đó, ta lưu kết quả của nó để trong tương lai, nếu sau này có gặp vấn đề đó sau này thì không phải tính lại nữa. Nếu một problem có thể chia nhỏ thành các sub- problem và các sub-problem này chồng chéo lên nhau, tức kết của sub-problem này dùng để giải các sub-problem kia thì đây là lúc cần dùng quy hoạch động "

Tham khảo: https://www.geeksforgeeks.org/
Đọc tiếp »

Thứ Bảy, 4 tháng 8, 2018

LINEAR ALGEBRA ( ĐẠI SỐ TUYẾN TÍNH )



  1. CHUYỂN VỊ VÀ CHUYỂN VỊ LIÊN HỢP
    Lý thuyết cơ sở
  • Chuyển vị

Cho A ∈ Rm*n, ta nói B ∈ Rm*n là chuyển vị của A nếu như bij=aji với mọi 1<= i <=n
và 1<= j <= m. 
Chuyển vị của một ma trận nhận được từ ma trận cũ thông qua phép phản xạ gương qua đường chéo chính của ma trận ban đầuKý hiệu: T

Nếu  ∈ Rm*n,  AT=A thì ma trận A được gọi là ma trận đối xứng.

Ví dụ:




  • Chuyển vị liên hợp

Định nghĩa giống với chuyển vị thông thường, tuy nhiên các thành phần của vector hay ma trận là số phức. Việc lấy chuyển vị đi kèm với lấy liên hợp phức. Ký hiệu : H
Nếu A ∈ Rm*n,  AH=A thì ma trận A được gọi là hermitan.

Ví dụ:


Implement by Python code




Problem: Tìm ma trận chuyển vị của ma trận a và vector b.

Solution: Sử dụng các lớp và hàm mà module numpy cung cấp

Cách implement 1: Ta sử dụng class array của module numpy, tạo ra hai đối tượng a và b.
sau đó ta tìm ma trận chuyển vị của hai ma trận trên bằng cách dùng hàm transpose của module numpy hỗ trợ.



Cách implement 2: Khi tìm ma trận chuyển vị, ta dùng hàm toán tử T của class array.


Kết quả giống nhau cho hai cách implement trên !





Các thuật ngữ tiếng anh dùng cho tra cứu:

Toán tử chuyển vị: Transpose operator
Ma trận đối xứng: Symmetric matrix
chuyển vị liên hợp: Conjugate transpose

Tham khảo tài liệu:
-Machine learning cơ bản- Vũ Hữu Tiệp

Edit bye me_BNT.



Mong nhận được đóng góp ý kiến từ độc giả.

Xin chân thành cảm ơn !






Đọc tiếp »

Median in a stream of intergers ( Part 1) [ Statistical Algorithms ]

Problem: Cho một dãy số interger được đọc từ 1 data stream. Tìm median của dãy online data.

Sau khi số đầu tiên của stream là 5 là median là 5

…….số thứ 2…………….. là 15, dãy số 5 , 15 là median là 10

…….số thứ 3 …. Là 1,dãy số 5,15,1 và median là 5

…….số thứ 4….là 3, dãy số là 5,15,1,3 và median là 4



Lưu ý: Cần sắp xếp trước khi tìm median. Output là median của dãy số interger đọc từ stream.
Một thuật toán như thế gọi là online algorithm.
" Any algorithm that can guarantee output of i-elements after processing i-th element, is said to be online algorithm "( Các định nghĩa luôn được giữ nguyên bảng bằng tiếng anh).

Có 3 solutions cho problem trên, chúng ta bắt đầu với giải pháp đầu tiên:

Method 1: Tư tưởng thuật toán insertion sort
Tóm tắt nội dung thuật toán insertion sort: Thuật toán này giả định ta có 1 nhóm phần tử đầu tiên đã được sắp xếp, ta lần lượt chèn các phần tử còn lại vào nhóm phần tử trên.

Ban đầu, nhóm phần tử đó chỉ là phần tử đầu tiên của dãy. Lập lần 1, ta chèn phần tử thứ 2 vào nhóm trên sao cho phù hợp, ta có số lượng của nhóm phần tử đầu tiên là 2, lập lần 3, ta số lượng nhóm phần tử đầu tiên là 3, cứ như thế lập n-1 lần ( với n là số lượng phần tử của dãy số ban đầu)  thì ta có được danh sách đã được sắp.

Quay trở lại problem trên, nếu ta có thể sắp xếp data ngay khi nó xuất hiện, chúng ta có thể dễ dàng xác định được median. Insertion sort là 1 online algorithm mà sắp xếp data ngay khi nó xuất hiện.

Ta thấy rằng sau khi sắp xếp element thứ i, i elements của mảng thì được sắp xếp. Insertion sort không phụ thuộc vào data tương lai. Điều này làm nó được gọi là online algorithm.

Tuy nhiên, insertion sort mất O(n^2) để sắp xếp n elements. Có lẽ chúng ta có thể dùng binary search trên insertion sort để vị trí của element kế tiếp trong time O(nlogn).

Tuy vậy, chúng ta không thể làm vậy để duy chuyển data trong time O(nlogn).
Nó mất polynomial time trong trường hợp insertion sort.


Implement: Full python code




Time complexity: O(n^2)

Mong nhận được đóng góp từ bạn đọc.
Xin chân thành cảm ơn !

Edit bye me_BNT

Đọc tiếp »
Liên hệ Bùi Ngọc Tài
Tôi sẽ rất vui lòng nếu nhận được sự phản hồi của các bạn. Nếu có gì chưa chính xác, hay nếu muốn đề xuất nội dung được viết trên https://buingoctai.blogspot.com/ thì hãy gửi yêu cầu đến tôi. Tôi sẽ cố gắng hỗ trợ các bạn một cách nhanh nhất và tốt nhất. Cảm ơn!


  • Email: buingoctai994@gmail.com
  • http:https://buingoctai.blogspot.com/
  • FACEBOOK: Bùi Ngọc Tài
Share Emphasis