.NET에서 매핑 및 축소
" Map and Reduce "알고리즘 의 사용을 보증하는 시나리오는 무엇입니까 ?
이 알고리즘의 .NET 구현이 있습니까?
Linq의 Map and Reduce와 동등한 기능 : linq를 가질만큼 운이 좋으면 자신 만의 맵을 작성하고 함수를 줄일 필요가 없습니다. C # 3.5와 Linq는 이미 다른 이름으로 사용하고 있습니다.
지도는
Select
:Enumerable.Range(1, 10).Select(x => x + 2);
감소
Aggregate
:Enumerable.Range(1, 10).Aggregate(0, (acc, x) => acc + x);
필터입니다
Where
:Enumerable.Range(1, 10).Where(x => x % 2 == 0);
https://www.justinshield.com/2011/06/mapreduce-in-c/
mapreduce 스타일 솔루션에 적합한 문제 클래스는 집계 문제입니다. 데이터 세트에서 데이터를 추출합니다. C #에서는 LINQ를 활용하여이 스타일로 프로그래밍 할 수 있습니다.
다음 기사에서 : http://codecube.net/2009/02/mapreduce-in-c-using-linq/
GroupBy 메소드는 맵 역할을하는 반면 Select 메소드는 중간 결과를 최종 결과 목록으로 줄이는 작업을 수행합니다.
var wordOccurrences = words
.GroupBy(w => w)
.Select(intermediate => new
{
Word = intermediate.Key,
Frequency = intermediate.Sum(w => 1)
})
.Where(w => w.Frequency > 10)
.OrderBy(w => w.Frequency);
분산 부분의 경우 DryadLINQ를 확인하십시오. http://research.microsoft.com/en-us/projects/dryadlinq/default.aspx
그 LINQ 그것을 호출 기억할 수 결코 때문에 Where
, Select
그리고 Aggregate
대신에 Filter
, Map
그리고 Reduce
내가 몇 확장 메서드를 만들어 있도록 사용할 수 있습니다 :
IEnumerable<string> myStrings = new List<string>() { "1", "2", "3", "4", "5" };
IEnumerable<int> convertedToInts = myStrings.Map(s => int.Parse(s));
IEnumerable<int> filteredInts = convertedToInts.Filter(i => i <= 3); // Keep 1,2,3
int sumOfAllInts = filteredInts.Reduce((sum, i) => sum + i); // Sum up all ints
Assert.Equal(6, sumOfAllInts); // 1+2+3 is 6
https://github.com/cs-util-com/cscore/blob/master/CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/collections/IEnumerableExtensions.cs 의 3 가지 방법은 다음과 같습니다 .
public static IEnumerable<R> Map<T, R>(this IEnumerable<T> self, Func<T, R> selector) {
return self.Select(selector);
}
public static T Reduce<T>(this IEnumerable<T> self, Func<T, T, T> func) {
return self.Aggregate(func);
}
public static IEnumerable<T> Filter<T>(this IEnumerable<T> self, Func<T, bool> predicate) {
return self.Where(predicate);
}
https://github.com/cs-util-com/cscore#ienumerable-extensions 에서 자세한 내용을 확인하십시오 .
당신이 구글의 자신의 버전을 작성하려고한다면, 그것은 그것을 보증 할 수 있습니다 .. !!!
심각하게도 몇 가지 작은 문제로 분해 할 수있는 문제가 있으면 Map-Reduce 솔루션이 작동합니다. MapReduce 의 Google 문서 에는 수천 개의 웹 페이지를 처리하고 문서의 단어 수 등을 포함하여 여러 가지 좋은 예가 있습니다.
참고 URL : https://stackoverflow.com/questions/428798/map-and-reduce-in-net
'programing tip' 카테고리의 다른 글
Spring Security를 사용한 단위 테스트 (0) | 2020.07.03 |
---|---|
TypeScript 주석의 구문은 어디에 기록되어 있습니까? (0) | 2020.07.03 |
ArrayAdapter를 사용하는 방법 (0) | 2020.07.03 |
배열에서 첫 x 항목 반환 (0) | 2020.07.03 |
나열 할 Pandas DataFrame 열 (0) | 2020.07.03 |