Friday 30 July 2021

How to associate point on a curve with points in an array of objects?

I have a bunch of names from the web (first name, last name, of people in different countries). Some of the countries have statistics on how many people have each last name, as shown in some places like here.

Well, that Japanese surname list only lists the top 100. I have other lists like for Vietnamese listing the top 20, and other lists the top 50 or 1000 even in some places. But I have real name lists that are up to the 1000+ count. So I might have 2000 Japanese surnames, with only 100 that have listed the actual count of people with that surname.

What I would like to do is built a "faker" sort of library, that generates realistic names based on these statistics. I know how to pick a random element from a weighted array in JavaScript, so once the "weights" (number of people with that name) are included for each name, it is just a matter of plugging it into that algorithm.

My question is, how can I "complete the curve" on the names that don't have a weight on them? That is, say we have an exponential-like curve sort of, from the 20 or 100 names that have weights on them. I would then like to randomly pick names from the remaining unweighted list, and give them a value that places them somewhat realistically in the remaining tail of the curve. How can that be done?

For example, here is a list of Vietnamese names with weights:

Nguyen,38
Tran,11
Le,9.5
Pham,7.1
Huynh,5.1
Phan,4.5
Vu,3.9
Đang,2.1
Bui,2
Do,1.4
Ho,1.3
Ngo,1.3
Duong,1
Ly,0.5

And here is a list without weights:

An
Ân
Bạch
Bành
Bao
Biên
Biện
Cam
Cảnh
Cảnh
Cao
Cái
Cát
Chân
Châu
Chiêm
Chu
Chung
Chử
Cổ
Cù
Cung
Cung
Củng
Cừu
Dịch
Diệp
Doãn
Dũ
Dung
Dư
Dữu
Đái
Đàm
Đào
Đậu
Điền
Đinh
Đoàn
Đồ
Đồng
Đổng
Đường
Giả
Giải
Gia
Giản
Giang
Giáp
Hà
Hạ
Hậ
Hác
Hàn
Hầu
Hình
Hoa
Hoắc
Hoạn
Hồng
Hứa
Hướng
Hy
Kha
Khâu
Khổng
Khuất
Kiều
Kim
Kỳ
Kỷ
La
Lạc
Lai
Lam
Lăng
Lãnh
Lâm
Lận
Lệ
Liên
Liêu
Liễu
Long
Lôi
Lục
Lư
Lữ
Lương
Lưu
Mã
Mạc
Mạch
Mai
Mạnh
Mao
Mẫn
Miêu
Minh
Mông
Ngân
Nghê
Nghiêm
Ngư
Ngưu
Nhạc
Nhan
Nhâm
Nhiếp
Nhiều
Nhung
Ninh
Nông
Ôn
Ổn
Ông
Phí
Phó
Phong
Phòng
Phù
Phùng
Phương
Quách
Quan
Quản
Quang
Quảng
Quế
Quyền
Sài
Sầm
Sử
Tạ
Tào
Tăng
Tân
Tần
Tất
Tề
Thạch
Thai
Thái
Thang
Thành
Thảo
Thân
Thi
Thích
Thiện
Thiệu
Thôi
Thủy
Thư
Thường
Tiền
Tiết
Tiêu
Tiêu
Tô
Tôn
Tôn
Tông
Tống
Trác
Trạch
Trại
Trang
Trầm
Trâu
Trì
Triệu
Trịnh
Trương
Từ
Tư
Tưởng
Úc
Ứng
Vạn
Văn
Vân
Vi
Vĩnh
Vũ
Vũ
Vương
Vưu
Xà
Xầm
Xế
Yên

I would like to randomize the list without weights (easy to do), and then assign each one a weight so it fills out the tail of the curve to some degree, so it feels somewhat realistic. How can this be done? Basically it seems we need to get the "curvature" of the initial weighted curve, and then somehow extend that with new items. It doesn't need to be perfect, but whatever can be done to approximate would be cool. I am not a statistics/math person so I don't really know where to begin on this one.

I don't have an exact outcome I want, I just want something that will generate the tail of the curve to some degree. For example, the start of the list might look like this:

An,0.5
Ân,0.45
Bạch,0.42
Bành,0.40
Bao,0.39
...

To try and visually demonstrate what I'm going after, the black boxes below are the provided data. The dotted boxes would stretch on for a long while, but here I show the start of it. The dotted boxes are what we would fill in in the curve so it fit the shape of the start of the curve.

▐
▐
▐▐
▐▐
▐▐
▐▐▐
▐▐▐ 
▐▐▐▐ 
▐▐▐▐▐▐ 
▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐░░░░
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐░░░░░░░░░░░░░░░░░░░░░
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

So basically, the left side of the curve are the few highest values. As it goes to the right, it gets smaller according to "some" pattern. We just need to roughly continue the pattern to the right, so it basically extends the curve.



from How to associate point on a curve with points in an array of objects?

No comments:

Post a Comment